CakePHP already offers a very useful set of default routes that allow any set of URL elements to be sent to the controller action as arguments. For example, a URL such as http://localhost/tags/view/cakephp
is interpreted as a call to the TagsController::view()
method, sending cakephp
as its first argument.
However, there are times when we need more flexibility when creating URLs with arguments, such as the ability to omit certain arguments or add others that may not have been specified in the method signature. Named
and GET
parameters allow us to have such flexibility, without losing the advantage of letting CakePHP deal with its automatic URL parsing.
To go through this recipe we need a sample table to work with. Create a table named categories
, using the following SQL statement:
CREATE TABLE `categories`( `id` INT UNSIGNED AUTO_INCREMENT NOT NULL, `name` VARCHAR(255) NOT NULL, PRIMARY KEY(`id`) );
Create a table named articles
, using the following...