Found out what I was missing.
In the controller, I removed ($slug) and instead, in the controller, I put the following code:
$slug = $this->params['slug'];
And it all works perfectly now!
Found out what I was missing.
In the controller, I removed ($slug) and instead, in the controller, I put the following code:
$slug = $this->params['slug'];
And it all works perfectly now!
Hi everyone,
I'm building a project with CakePHP and I would like to be able to have pages that are created dynamically. So, if a user goes to www.domain.com/page-name, the controller should take the /page-name part of the URL, search the database for it, and then display the results in a specific page.
However, I'm unable to get the /page-name part of the URL and pass it to the controller. So far, I have this in my routes.php file:
Router::connect('/:slug', array('controller' => 'contents', 'action' => 'dynamicpage'), array('slug' => '[a-zA-Z0-9_-]+'));
And I have this code in my controller file:
function dynamicpage($slug) {
$page = $this->Content->find('first', array('conditions' => array('Content.slug' => $slug)));
$this->set('page', $page);
$this->pageTitle = "";
}
Have I missed a step somewhere? Or isn't what I want to do possible?