This post explains about how to implement CMS application with SEO friendly URLs in CakePHP, earlier we learned about SEO / Clean URLs in PHP and custom CMS application, now its time to learn in CakePHP. After long time I am writing article in CakePHP. CakePHP is a MVC framework which we can implement large scale websites / applications.
Download CakePHP files from site and upload files into your document directory and run the application, which is already we discussed in earlier post i.e. About CakePHP (now version changed but procedure is same)
In your folders : CakePHP -> app -> webroot -> .htaccess
1 2 3 4 5 6 | <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ index.php [QSA,L] </IfModule> |
a simple CMS based application implement in CakePHP then controller as look like
Controller:
1 2 3 4 5 6 7 8 9 | class PagesController extends AppController { public $helpers = array('Html', 'Form'); public function aboutus() { $this->layout = 'pages'; $aboutus = $this->Pages->find('first', array('conditions' => array('Page.type' => 'aboutus'))); $this->set('title_for_layout', 'Aboutus - Anil Labs'); $this->set('content', $aboutus); } } |
Model:
1 2 3 4 | class Page extends AppModel { public $name = 'Page'; } |
We can write beforeValidate(), beforeSave(), validate … but here we don’t need application.
View:
CakePHP -> app -> view -> pages -> aboutus.ctp
you can write your own styles in this file
Layout:
1 2 3 4 5 6 7 | <html> <head> <title><?php echo $title_for_layout ?></title> </head> <body><?php echo $this->fetch('content'); ?> </body> </html> |
in your folders : CakePHP -> app -> Config -> routes.php
1 2 3 4 |
you can access the application with
[domain name]/aboutus
We can implement remaining pages also to complete CMS ( content management system ) with SEO friendly URLs in CakePHP.
0 Comments