views:

1163

answers:

3

I'm new to CakePHP but I've been though their FAQs and guides to no avail. This is so simple that I just must not be thinking straight:

How can I access a parameter sent through the URL within my view files?

Example: http://example.com/view/6

How would I take that parameter ("6") and cycle it through the controller to another view page?

If that's too complex for a quick answer, how can I reference the 6 within the view page itself? The 6 in this situation is the "Id" value in my database, and I need to set it as the "parent" -

Thanks

+2  A: 

The URL, as you have it, will call the 6() method of your ViewController, which is not a valid method name. You may have to play with your routes to make that work.

If you don't want to configure your routes, you'll need the controller in the URL, like so:

http://example.com/thinger/view/6

which will call thingerControllerObject->view("6"). If you want "/view/" to go to a different method, edit the routes. See:

Lucas Oman
+1  A: 

To access the parameter in your view look in $this->params

neilcrookes
A: 

Parameters can be retrieved like this

$this->params['pass']

Returns an array (numerically indexed) of URL parameters after the Action.

// URL: /posts/view/12/print/narrow
Array
(
    [0] => 12
    [1] => print
    [2] => narrow
)
nrhm