Friday, August 9, 2013

How to get your first CakePHP tutorial work on WAMP?

In getting first CakePHP example works on WAMP, steps below illustrated how I get through.

1. Download CakePHP framework from GitHub:
2. Unzip CakePHP source code and place it in
"[WAMP_INSTALL_PATH]\wamp\www\cakephp" directory.
3. Create Post.php in "/app/Model" directory.
    class Post extends AppModel {
4. Create PostsController.php in "/app/Controller" directory.
class PostsController extends AppController {
    public $helpers = array('Html', 'Form');
  public function index() {
        $this->set('posts', $this->Post->find('all'));
5. Create index.ctp in "/app/View" directory.
<h1>Blog posts</h1>

    <!-- Here is where we loop through our $posts array, printing out post info -->

    <?php foreach ($posts as $post): ?>
        <td><?php echo $post['Post']['id']; ?></td>
            <?php echo $this->Html->link($post['Post']['title'],
array('controller' => 'posts', 'action' => 'view', $post['Post']['id'])); ?>
        <td><?php echo $post['Post']['created']; ?></td>
    <?php endforeach; ?>
    <?php unset($post); ?>

Note: To get this example to work on WAMP, uncomment "LoadModule rewrite_module modules/" 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: