Monday, May 3, 2010

Re: Newbie problem with 15 minute blog in Cake 1.3

http://yourapp/foos/bar/id:1/ will not work when Cake is expecting
http://yourapp/foos/bar/1

Cake doesn't know the name of your function variables (I don't even
think there's a way to determine that in PHP). So it wouldn't know
that the 'id' named param is supposed to be the first argument in
FoosController::bar($id, [$var2, $var3...]). If you want to use named
parameters, then you need to define a custom route and tell CakePHP to
pass the named parameters to the action and the order to pass them in.
Otherwise, you'll have to use $this->passedArgs['id'] in the action.

See the cookbook: http://book.cakephp.org/view/949/Passing-parameters-to-action

On May 2, 3:58 pm, Sam Sherlock <sam.sherl...@gmail.com> wrote:
> you can access it
>
> $this->params['named']['id']
>
> your view action may take it as argument (in controller)
> ..
> function view($id) {
> ...}
>
> ..
>
> ----
>
> You can alter posts routes should you want to use slugs rather than ids with
> Syrup.Sluggable  (syrup is a cake plugin that has a few behaviours)
>
> - S
>
> On 2 May 2010 23:27, Matt <mattlavin...@gmail.com> wrote:
>
>
>
> > > The controller has the 'params' property. If you output this:
> > > debug($this->params); //from your view
> > > I believe you should see your id showing in the 'pass' array if
> > everything
> > > is working. If it's there, this will confirm the value is getting all the
> > > way in to your controller or not. If it's there, then to problem isn't in
> > > the mod-rewrite or anything early in the process.
>
> > > Don
>
> > Thanks for the tip.  Added the debug code and pasting the output
> > below.   ID is in the "named" element but not the "pass" element.  Is
> > that a problem?
>
> > Array
> > (
> >    [controller] => posts
> >    [action] => view
> >    [named] => Array
> >        (
> >            [id] => 3
> >        )
>
> >    [pass] => Array
> >        (
> >        )
>
> >    [plugin] =>
> >    [form] => Array
> >        (
> >        )
>
> >    [url] => Array
> >        (
> >            [url] => posts/view/id:3
> >        )
>
> >    [models] => Array
> >        (
> >            [0] => Post
> >        )
>
> > )
>
> > Check out the new CakePHP Questions sitehttp://cakeqs.organd help others
> > with their CakePHP related questions.
>
> > 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
> > cake-php+unsubscribe@googlegroups.com<cake-php%2Bunsubscribe@googlegroups.com>For more options, visit this group at
> >http://groups.google.com/group/cake-php?hl=en
>
> Check out the new CakePHP Questions sitehttp://cakeqs.organd help others with their CakePHP related questions.
>
> 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
> cake-php+unsubscribe@googlegroups.com For more options, visit this group athttp://groups.google.com/group/cake-php?hl=en

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.

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
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

No comments: