1. Download CakePHP framework from GitHub: https://github.com/cakephp/cakephp/tags
2. Unzip CakePHP source code and place it in
"[WAMP_INSTALL_PATH]\wamp\www\cakephp" directory.
3. Create Post.php in "/app/Model" directory.
<?php class Post extends AppModel { } ?>
<?php class PostsController extends AppController { public $helpers = array('Html', 'Form'); public function index() { $this->set('posts', $this->Post->find('all')); } } ?>
<h1>Blog posts</h1> <table> <tr> <th>Id</th> <th>Title</th> <th>Created</th> </tr> <!-- Here is where we loop through our $posts array, printing out post info --> <?php foreach ($posts as $post): ?> <tr> <td><?php echo $post['Post']['id']; ?></td> <td> <?php echo $this->Html->link($post['Post']['title'], array('controller' => 'posts', 'action' => 'view', $post['Post']['id'])); ?> </td> <td><?php echo $post['Post']['created']; ?></td> </tr> <?php endforeach; ?> <?php unset($post); ?> </table>
Note: To get this example to work on WAMP, uncomment "LoadModule rewrite_module modules/mod_rewrite.so" in httpd.conf file. Restart Apache Web Server.
6. Type in "http://localhost/cakephp/posts/index" in your browser to access this example.
Once able to get the first example to work, please follow with the example provided in CakePHP website to continue with the further exploration.
No comments:
Post a Comment