Re: Dynamic Navigation in a Layout. How?

2008-12-10 Thread Rob Wilkerson

On Tue, Dec 9, 2008 at 10:49 PM, Adam Royle <[EMAIL PROTECTED]> wrote:
>
> Put that call in a method, instead of just stranded in the middle of a
> class definition...
>
> class AppController extends Controller {
>var $uses = array ( 'NavMenu' );
>function beforeRender() {
>$this->set ( 'primaryNav', $this->NavMenu->find ( 'all' ) );
>}
> }

That's what I was missing. I knew it had to be something simple,
stupid. Your contributions to my sanity are appreciated and
documented.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Dynamic Navigation in a Layout. How?

2008-12-09 Thread Adam Royle

Put that call in a method, instead of just stranded in the middle of a
class definition...

class AppController extends Controller {
var $uses = array ( 'NavMenu' );
function beforeRender() {
$this->set ( 'primaryNav', $this->NavMenu->find ( 'all' ) );
}
}

On Dec 10, 12:11 pm, Rob Wilkerson <[EMAIL PROTECTED]> wrote:
> On Dec 7, 1:51 pm, Rob <[EMAIL PROTECTED]> wrote:
>
> > Just do a find on your NavMenu in the model you are driving your view
> > from, and then you can access the data from your element.
>
> Okay, I'd like to pretend that I'm not getting my ass thoroughly
> kicked by this, but...doing so isn't helping me sort this out. The
> solution I'm trying at the moment is this: tell the AppController to
> use the NavMenu model and then create a getMenuItems() function that
> accepts a parameter indication which menu should be retrieved. The
> function would return an array of menu items for that menu.
> Unfortunately, I'm not getting very far at all.
>
> For the moment, I just have this to see what I can see:
>
> class AppController extends Controller {
>         var $uses = array ( 'NavMenu' );
>
>         $this->set ( 'primaryNav', $this->NavMenu->find ( 'all' ) );
>
> }
>
> What I see is an error in the set() method call: Parse error: syntax
> error, unexpected T_STRING, expecting T_FUNCTION in /path/to/my/app/
> app_controller.php on line 42.
>
> Look, I know I'm probably doing something incredibly stupid here, but
> the documentation just doesn't offer any help at all for including
> dynamic content in a layout and my frustration is starting to show.
> Can someone point me in the right direction and, if possible, provide
> some very lightweight, dummy code that helps me put the pieces
> together? requestAction() seems to be a discouraged solution these
> days, so I'm trying a different route, but I'm not sure that it's the
> "cake way", nor can I find much information about what the "cake way"
> actually is for this scenario.
>
> I appreciate the help folks have tried to give so far, I'm just to new
> to Cake to skip steps. I need the remedial version, it's become quite
> clear. :-)
>
> Thanks.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Dynamic Navigation in a Layout. How?

2008-12-09 Thread Rob Wilkerson


On Dec 7, 1:51 pm, Rob <[EMAIL PROTECTED]> wrote:
> Just do a find on your NavMenu in the model you are driving your view
> from, and then you can access the data from your element.

Okay, I'd like to pretend that I'm not getting my ass thoroughly
kicked by this, but...doing so isn't helping me sort this out. The
solution I'm trying at the moment is this: tell the AppController to
use the NavMenu model and then create a getMenuItems() function that
accepts a parameter indication which menu should be retrieved. The
function would return an array of menu items for that menu.
Unfortunately, I'm not getting very far at all.

For the moment, I just have this to see what I can see:

class AppController extends Controller {
var $uses = array ( 'NavMenu' );

$this->set ( 'primaryNav', $this->NavMenu->find ( 'all' ) );
}

What I see is an error in the set() method call: Parse error: syntax
error, unexpected T_STRING, expecting T_FUNCTION in /path/to/my/app/
app_controller.php on line 42.

Look, I know I'm probably doing something incredibly stupid here, but
the documentation just doesn't offer any help at all for including
dynamic content in a layout and my frustration is starting to show.
Can someone point me in the right direction and, if possible, provide
some very lightweight, dummy code that helps me put the pieces
together? requestAction() seems to be a discouraged solution these
days, so I'm trying a different route, but I'm not sure that it's the
"cake way", nor can I find much information about what the "cake way"
actually is for this scenario.

I appreciate the help folks have tried to give so far, I'm just to new
to Cake to skip steps. I need the remedial version, it's become quite
clear. :-)

Thanks.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Dynamic Navigation in a Layout. How?

2008-12-07 Thread Rob

Just do a find on your NavMenu in the model you are driving your view
from, and then you can access the data from your element.

I do this on my site in my "jobs" view, where I want to display a
couple differently filtered lists of "job slots". I populate the lists
into $userSlots and $availableSlots in my jobs_controller, then in my
view, I use the same element to display them by passing in those two
data sets:



element('signup_list', array( 'slots' =>
$userSlots )); ?>



element('signup_list', array( 'slots' =>
$availableSlots )); ?>

Nobody signed up for this job yet




On Dec 7, 8:08 am, Rob Wilkerson <[EMAIL PROTECTED]> wrote:
> On Dec 7, 10:59 am, Rob <[EMAIL PROTECTED]> wrote:
>
> > Elements are definitely the way to go. I make extensive use of
> > elements for common display items.
>
> Okay, good. At least I'm not _way_ off base, then. Now, the follow-on
> question is this: how do I make an element data-driven? In my case,
> I'd want my element to have access to the NavMenu model in order to
> retrieve the items in any given menu. I haven't found much (read:
> anything) documented on this.
>
> > On the other hand, if you are just driving a common navigation, I'm
> > not sure you need an element since it can just go directly into the
> > layout.
>
> Except that it's data-driven and exists with slight variations in 3
> different locations within the layout.
>
> Thanks again.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Dynamic Navigation in a Layout. How?

2008-12-07 Thread Filip Camerman

What you need is indeed an element, and to query the database from
inside an element you can use requestAction in it (that's what it's
there for).

It's explained here:
http://book.cakephp.org/view/434/requestAction

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Dynamic Navigation in a Layout. How?

2008-12-07 Thread Rob Wilkerson


On Dec 7, 10:59 am, Rob <[EMAIL PROTECTED]> wrote:
> Elements are definitely the way to go. I make extensive use of
> elements for common display items.

Okay, good. At least I'm not _way_ off base, then. Now, the follow-on
question is this: how do I make an element data-driven? In my case,
I'd want my element to have access to the NavMenu model in order to
retrieve the items in any given menu. I haven't found much (read:
anything) documented on this.

> On the other hand, if you are just driving a common navigation, I'm
> not sure you need an element since it can just go directly into the
> layout.

Except that it's data-driven and exists with slight variations in 3
different locations within the layout.

Thanks again.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Dynamic Navigation in a Layout. How?

2008-12-07 Thread Rob

Elements are definitely the way to go. I make extensive use of
elements for common display items.

On the other hand, if you are just driving a common navigation, I'm
not sure you need an element since it can just go directly into the
layout.

On Dec 7, 5:24 am, Rob Wilkerson <[EMAIL PROTECTED]> wrote:
> Rob Wilkerson wrote:
> > I'm so new to Cake that I'm honestly not even sure how to best ask
> > this question (much less search to see whether it's been asked), so
> > I'm going to describe what I have and allow the question of how best
> > to achieve the result to be implied.
>
> > I have a layout (my default layout) that includes 3 different
> > navigation menus (primary, secondary, tertiary).  Those menus are data
> > driven - I have a nav_menus table that hasAndBelongsToMany
> > nav_menu_items. I'd like to populate those menu instances dynamically
> > in each place where they belong on the layout.  I'd like to share the
> > logic that will retrieve the items based on the menu and use that to
> > output the expected markup:
>
> > 
> >    Home
> >    Directions
> >    Contact
> > 
>
> > I'm not sure where to look to get started. I have dug around some, but
> > I haven't seen anything that seems to address this particular need in
> > a way that I can digest it as such.
>
> > Thanks.
>
> I got pulled away from this for a while, but I'm trying to get back to
> it so I wanted to revisit this question. validkeys suggested using a
> component, but the more I look at it the less it seems right (at least
> from a total n00b's perspective). I'm trying to insert data-driven
> output into a _layout_. If I use a component, then I'd have to specify
> the use of that component for every controller that uses that
> template.
>
> Is there not a more "universal" way to tell the template to include
> dynamic content? It seems like an element (provided I can figure out
> how to give it data access without breaking encapsulation) is the
> right way to go.
>
> Any thoughts?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Dynamic Navigation in a Layout. How?

2008-12-07 Thread Rob Wilkerson


Rob Wilkerson wrote:
> I'm so new to Cake that I'm honestly not even sure how to best ask
> this question (much less search to see whether it's been asked), so
> I'm going to describe what I have and allow the question of how best
> to achieve the result to be implied.
>
> I have a layout (my default layout) that includes 3 different
> navigation menus (primary, secondary, tertiary).  Those menus are data
> driven - I have a nav_menus table that hasAndBelongsToMany
> nav_menu_items. I'd like to populate those menu instances dynamically
> in each place where they belong on the layout.  I'd like to share the
> logic that will retrieve the items based on the menu and use that to
> output the expected markup:
>
> 
>   Home
>   Directions
>   Contact
> 
>
> I'm not sure where to look to get started. I have dug around some, but
> I haven't seen anything that seems to address this particular need in
> a way that I can digest it as such.
>
> Thanks.

I got pulled away from this for a while, but I'm trying to get back to
it so I wanted to revisit this question. validkeys suggested using a
component, but the more I look at it the less it seems right (at least
from a total n00b's perspective). I'm trying to insert data-driven
output into a _layout_. If I use a component, then I'd have to specify
the use of that component for every controller that uses that
template.

Is there not a more "universal" way to tell the template to include
dynamic content? It seems like an element (provided I can figure out
how to give it data access without breaking encapsulation) is the
right way to go.

Any thoughts?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Dynamic Navigation in a Layout. How?

2008-11-11 Thread Rob Wilkerson


On Nov 11, 12:06 pm, validkeys <[EMAIL PROTECTED]>
wrote:
> Yeah, I didn't include the query on the model here, I inferred it when
> saying that you should import the NavMenu model into the component
>
> Make more sense?

I dunno, maybe.  I'm probably too new to Cake to accurately understand
inferences. :-)

Generally speaking, don't you often see find() operations executed
within the controller? To me, that seems more encapsulated than
importing the entire model into the component (if that's actually what
I'm doing). I'll dig more into App::imnport() and see what's going on
in there.

Thanks again.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Dynamic Navigation in a Layout. How?

2008-11-11 Thread validkeys

Yeah, I didn't include the query on the model here, I inferred it when
saying that you should import the NavMenu model into the component

Make more sense?

On Nov 11, 8:34 am, Rob Wilkerson <[EMAIL PROTECTED]> wrote:
> On Nov 10, 9:16 pm, validkeys <[EMAIL PROTECTED]> wrote:
>
> > Well first, it sounds like you want to create a component
>
> > Class NavComponent extends Object {}
>
> > It sounds like from your message that all 3 navs are on the same page,
> > you just want to be able to control the links that are in each. Am I
> > right?
>
> That's correct.
>
> > 3. Populate each array with their respective items
> >  >         $nav_1[] = array(
> >                         'title' => 'Home',
> >                         'controller' => 'pages',
> >                         'action' => 'display',
> >                         'id' => 1
> >                 )
> > ?>
>
> Wouldn't the array be populated by a query on the model? I know it's
> not the proper syntax, but in pseudo-code:
>
> $primary_nav = find ( nav_menu_items where nav_menu = 'primary nav
> id' );
>
> Thanks for your help. I'll dig more into this now that I have a
> starting point and that may answer some of my follow on questions.  I
> really am _that_ new to Cake so I'm kind of making this up as I go
> along. :-)
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Dynamic Navigation in a Layout. How?

2008-11-11 Thread Rob Wilkerson



On Nov 10, 9:16 pm, validkeys <[EMAIL PROTECTED]> wrote:
> Well first, it sounds like you want to create a component
>
> Class NavComponent extends Object {}
>
> It sounds like from your message that all 3 navs are on the same page,
> you just want to be able to control the links that are in each. Am I
> right?

That's correct.

> 3. Populate each array with their respective items
>          $nav_1[] = array(
>                         'title' => 'Home',
>                         'controller' => 'pages',
>                         'action' => 'display',
>                         'id' => 1
>                 )
> ?>

Wouldn't the array be populated by a query on the model? I know it's
not the proper syntax, but in pseudo-code:

$primary_nav = find ( nav_menu_items where nav_menu = 'primary nav
id' );

Thanks for your help. I'll dig more into this now that I have a
starting point and that may answer some of my follow on questions.  I
really am _that_ new to Cake so I'm kind of making this up as I go
along. :-)
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Dynamic Navigation in a Layout. How?

2008-11-10 Thread validkeys

Well first, it sounds like you want to create a component

Class NavComponent extends Object {}

It sounds like from your message that all 3 navs are on the same page,
you just want to be able to control the links that are in each. Am I
right?

1. What I would do in that case is in the initialize or startup
function of the component is import the nav model
App::Import('Model','NavMenu');

2. Create 3 arrays (nav_1, nav_2, nav_3)

3. Populate each array with their respective items
 'Home',
'controller' => 'pages',
'action' => 'display',
'id' => 1
)
?>




4. Then set those variables ($this-
>set(compact('nav_1','nav_2','nav_3'))

5. Then in your layout, in each section where the nav is supposed to
be

ex. Nav_1


link($item['title'],array('controller'=>
$item['controller'],'action'=>$item['action'],$item['id'])) ?>



Does that help?







On Nov 10, 5:31 pm, Rob Wilkerson <[EMAIL PROTECTED]> wrote:
> I'm so new to Cake that I'm honestly not even sure how to best ask
> this question (much less search to see whether it's been asked), so
> I'm going to describe what I have and allow the question of how best
> to achieve the result to be implied.
>
> I have a layout (my default layout) that includes 3 different
> navigation menus (primary, secondary, tertiary).  Those menus are data
> driven - I have a nav_menus table that hasAndBelongsToMany
> nav_menu_items. I'd like to populate those menu instances dynamically
> in each place where they belong on the layout.  I'd like to share the
> logic that will retrieve the items based on the menu and use that to
> output the expected markup:
>
> 
>         Home
>         Directions
>         Contact
> 
>
> I'm not sure where to look to get started. I have dug around some, but
> I haven't seen anything that seems to address this particular need in
> a way that I can digest it as such.
>
> Thanks.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---