Reputation: 28793
I'm wanting to create a series of pages using CakePHP. I know you can simply create a view inside the pages folder but what if I wanted to build hierarchical pages like: /legal/policy/
Also if for example I wanted /legal/ to not exist ie. act only as a prefix how would I also do that?
So two questions:
1.) How to create hierarchical pages 2.) How to create prefixes like /legal/ so domain.com/legal would throw 404 but domain.com/legal/policy would show a page
Thanks
Upvotes: 0
Views: 2465
Reputation: 1344
You could put your view in the following:
/app/views/pages/legal/policy.ctp
It would then be accessible via: www.example.com/pages/legal/policy
If you want to remove the /pages/ from the URL then use routing as Travis Leleu suggests.
Upvotes: 1
Reputation: 4230
What you're doing is handled by routing in CakePHP. Check in the manual under the Pages section.
Basically, you're going to create a Route similar to as follows, in routes.php:
Router::connect( '/legal/:page', array( 'controller' => 'pages' /* or other controllers */, 'action' => 'display'), array( 'pass' => array( 'page' ) );
That will connect /legal/* to PagesController::display( $page = null ), with the first parameter (after "legal/") passed as $page.
That answers #1.
For #2, I would recommend just checking to see if $page is null. If it is, then you're at the root for that route (/legal/). Just do a redirect inside your PagesController over to your 404 page from there.
Upvotes: 1