Archive for the ‘CakePHP’ Category

CakePHP Time Helper: how to use it in a view

Monday, March 8th, 2010

First of all, in the controller, add it to the $helpers array:

var $helpers = array(‘Html’, ‘Form’, ‘Time’);

Then in the corresponding view, call it like this:

<p>Date Published: <?=$time->nice($post['Post']['date']);?></p>

which effectively (in this case from the database in this example) turns this: 2010-01-02 21:54:00

into this: Sat, Jan 2nd 2010, 21:54

—- note: —-

without the Time helper we could of course do this specific thing with the plain ‘ol PHP date function this way:

<?=date(‘M jS Y, g:i a’,strtotime($post['Post']['date']));?>

—-

$post['Post']['date'] is the value of the object Time will beautify, in this case

sent by the following function in the controller:

function view($id = null) {

if (!$id) {

$this->Session->setFlash(__(‘Invalid Post.’, true));
$this->redirect(array(‘action’=>’index’));

}
$this->set(‘post’, $this->Post->read(null, $id));

}

CakePHP debug

Monday, March 8th, 2010

need to see inside that specified array?

to be remembered:

app/views/posts/view.ctp

<? debug($post); ?>

which will also display records from associated models!

CakePHP Setting up command line to bake

Monday, March 1st, 2010

http://i.justrealized.com/2009/02/16/how-to-run-xampps-php-cli-and-cakephp-console/

start baking:

C:\xampp\htdocs\project\app>”../cake/console/cake” bake