Routing maps your URL to unique controller’s movement. on this phase, we are able to see how you can put in force routes, how you may skip arguments from URL to controller’s action, how you may generate URLs, and the way you can redirect to a specific URL. usually, routes are carried out in record config/routes.php. Routing can be applied in two ways
Here is an instance imparting each the sorts.
Each the techniques will execute the index approach of ArticlesController. Out of the two methods scoped path builder offers better overall performance.
Router::join() approach is used to connect routes. the following is the syntax of the technique –
There are 3 arguments to the Router::connect() method −
Here is the fundamental format of a path −
Make modifications within the config/routes.php document as proven under.
Create a TestsController.php document at src/Controller/TestsController.php. copy the subsequent code in the controller document.
Create a folder tests under src/Template and beneath that folder create a View file called index.ctp. replica the following code in that file.
Complete the above instance by visiting the next URL.
The above URL will yield the subsequent output.
Exceeded arguments are the arguments which are surpassed in the URL. these arguments may be surpassed to controller’s movement. those passed arguments are given to your controller in 3 ways.
Following instance suggests how we can pass arguments to the action of the controller.
Go to the subsequent URL − http://localhost:85/CakePHP/tests/value1/value2
This can suit the following path line.
Here the value1 from URL can be assigned to arg1 and value2 could be assigned to arg2.
Once the argument is passed to the controller’s action, you can get the argument with the following assertion.
The arguments surpassed to controller’s movement will be stored in $args variable.
The argument can also be exceeded to movement through the subsequent statement −
The above announcement will skip two arguments 5, and six to TestController’s index() technique.
Make changes within the config/routes.php document as proven in the following program.
Create a TestsController.php file at src/Controller/TestsController.php. Copy the following code in the controller file.
Create a folder Tests at src/Template and under that folder create a View file called index.ctp. Copy the following code in that file.
Execute the above example by visiting the following URL.
Upon execution, the above URL will produce the following output.
CakePHP Related Interview Questions
|PHP Interview Questions||MySQL Interview Questions|
|PHP+MySQL Interview Questions||Drupal Interview Questions|
|MYSQL DBA Interview Questions||PHP5 Interview Questions|
|WordPress Interview Questions||Joomla Interview Questions|
|CakePHP Interview Questions||CodeIgniter Interview Questions|
|PHP7 Interview Questions|
All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.