Archive for the ‘CakePHP’ Category

CakePHP Setting up your system to Bake

Tuesday, February 1st, 2011

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

Starting a new project with CakePHP

Tuesday, February 1st, 2011

download the current release:

cakephp.org

unzip, copy/rename folder as desired

check apache file permissions
app/tmp – 0777

app/config
core.php – change Security.salt to new value
database.php.default – remove .default, and configure values according to your database

done

CakePHP naming conventions

Tuesday, February 1st, 2011

URL will trigger controller
example:
http://appname.com/data_users

in app/controllers:
data_users_controller.php
in there:
class DataUsersController extends Controller {
}

this should be the same as the table it will reference:
data_users

in app/models:
data_user.php
class data_user extends AppModel {
}

in app/views/data_users:
function.ctp

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