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
Cakephp get url parameters Syntax – // Get the Passed arguments $this->request->pass; $this->request['pass']; $this->request->params['pass']; The above syntax will give you the arguments of url passed along with controller.
You can retrieve post data as Array. $post_data= $this->request->data; You can retrieve post data for particular key.
Routing provides you tools that map URLs to controller actions. By defining routes, you can separate how your application is implemented from how its URLs are structured. Routing in CakePHP also encompasses the idea of reverse routing, where an array of parameters can be transformed into a URL string.
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
)
To access the parameter in your view look in $this->params
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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With