TOP

CakePHP: HTML Link

The HTML helper is pretty useful, here’s how you write a link in a view file:

<?php 
echo $html->link('click me',
     array(
          'controller'=>'users',
          'action'=>'index'
     )
);
 ?>

The parameters in this are:

  • title (what you actually click on)
  • link location array(controller, action, id (if needed for edit))
  • (optional) attributes array
  • TOP

    CakePHP: find all records

    $this->set('posts',$this->Post->find('all'));

    Typically for an index action, like this (in the controller context):

    Location: /app/controllers/posts_controller.php

    <?php
    class PostsController extends AppController{
         var $name = 'Posts';
     
         function index(){
             $this->set('posts',$this->Post->find('all'));
         }
    }
    ?>