How to implement CMS application with SEO friendly URLs in CakePHP

in CakePHP, Framework / No Comments

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.

How to implement CMS application with SEO friendly URLs in CakePHP by Anil Kumar Panigrahi

How to implement CMS application with SEO friendly URLs in CakePHP by Anil Kumar Panigrahi

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

<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:

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:

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:

<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

Router::connect(
        '/aboutus',
        array('controller' => 'pages', 'action' => 'aboutus')
    );

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.

With more than 9 years experience in PHP and Founder of Anil Labs, a blog for PHP and related posts. contributed posts regarding CodeIgniter, CakePHP and Learn PHP online ...Contact : [email protected]

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>