I started learning cakephp2 and was following the basic tutorial. But I find most of the tutorials out there complicated and hard to understand. I want to a make a simple site that allows the user to transition to the item page from shop list page. I want the url to display like (sample.com/shoplist/items).maybe I'm having trouble with Controller. It would be great help if a simple there are some simple sample. I would love to hear from you.
If you consider the usual use of the framework, you have: domain/controller/action
as the URL. CakePHP will look for a View
file with the same name as the action
to show on the window.
So, one way to accomplish what you've discussed, would be to have a controller
named ShoplistController.php
where you can have index
as the action for the main View, which should be called index.ctp
.
Then, when the user wants to look at items, these could happen with an action called items
, which would demand the View file items.ctp
.
However, it's important to note that while working with CakePHP (And other MVC frameworks), it's best to organize Models, Controllers, and Views based on their actual jobs and responsibilities, not the URL they build.
It's also important to note that the suggestions I'm providing here assume everything is in the right place: Controller
file in the app/Controller
directory and Views
in the app/View/Shoplist
directory.