Tuesday, November 9, 2010

Static Pages

Not all pages in your site will be dynamic. Some pages, such as an "About" page, will be static and CakePHP has a Pages controller for just that purpose. The pages controller is located by default in /cake/libs/controllers/pages_controller.php If you need to edit it for any reason, copy the file to /app/controllers/

Static pages are stored in /app/views/pages/ and displayed using the display action. By default they are addressed using site root/pages/page name.

Create any static pages with the .ctp extension and include any html formatting you want in your page.

Create /app/views/pages/about.ctp
<?php $this->set("title_for_layout", 'About Drug-ed.com'); ?>
<h2>About Drug-Ed.com</h2>
<p>Drug-Ed.com is a free drug education and medication reminder service for your daily medication needs. Set up your drug schedule online and have reminders emailed to you or texted to your mobile phone daily. We want to make taking your medication as easy and hassle free as possible.</p>
Remember when I said we should change the page title in the controller? Well with static pages it is easier to just set them in the page itself.

Save and upload the file then browse to http://drug-ed.com/pages/about

When using the HTML helper to create links to static pages remember that pages is the controller and display is the action so they either must be explicitly declared, or create a hard link instead.
<?php echo $this->Html->link('Downloads', array('controller' => 'pages', 'action'=>'display', 'downloads')); ?>
<?php echo $this->Html->link('Downloads', '/pages/downloads'); ?>

No comments:

Post a Comment