step 15: adding element in cakephp blog

step 15: adding element in cakephp blog

To add element in cakephp blog we need to make two changes as follows:

1. Making New Element:
Create a file located at “/app/views/elements/latest.ctp" then copy & past the blow code.


   <h2>Recent Posts</h2>
      <li><a href="">this is a test title</a></li>
      <li><a href="">this is another test title</a></li>
      <li><a href="">this is also a test title</a></li>

2. Homepage or Default Layout Modification:
Now open up the default layout file located at “/app/views/layouts/default.ctp" then replace the code as bellow.


   <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "">
   <html xmlns="">
     <title>20 steps to make cakephp blog</title>
     <?php echo $html->css('style.css'); ?>
     <div id="wrapper">
      <div id="header-wrapper">
       <div id="header">
        <div id="logo">
         <a href="<?php echo $html->url('/pages/home'); ?>"><h1><span>cakephp</span> blog</h1></a>
        <div id="menu">
           <li><a href="<?php echo $html->url('/pages/home'); ?>">Home</a></li>
           <li><a href="<?php echo $html->url('/posts'); ?>">Posts</a></li>
           <li><a href="<?php echo $html->url('/posts/admin'); ?>">Admin</a></li>
      <div id="page">
       <div id="errors">
         if($session->check('Message.flash')) $session->flash();
         if($session->check('Message.auth')) $session->flash('auth');
       <div style="clear: both; height:2px;"> </div>
       <div id="content">
        <div class="post">
         <?php echo $content_for_layout; ?>
       <div id="sidebar">
            <?php echo $this->element('latest'); ?>
       <div style="clear: both; height:2px;"> </div>
     <div id="footer">
      <p>Copyright (c) 2010 CakePHP Blog</p>

Finally open your browser and get the element on Homepage or Default Layout in CakePHP Blog Project "http://localhost/cakeblog/" as follows:


Related Tutorial Examples

  1. step 12: add post view controller cakephp blog
  2. step 13: edit post view controller cakephp blog
  3. step 14: delete post view controller cakephp blog
  4. step 16: passing data into element in cakephp blog
  5. step 17: routes configuration cakephp blog project
  6. MySQL least() Function Numeric Value Example
  7. MySQL greatest() Function Datetime Example
  8. MySQL now() Datetime Function Example
  9. MySQL NULLIF() Nested Function Example

No comments:

Post a Comment

leave your comments here..