Archive for the 'CakePHP' Category

Retrieving data in CakePHP

April 23, 2008

A function to retrieve data in CakePHP is the findAll() model function.
It has the following syntax:
PLAIN TEXT
PHP:

findAll($conditions, $fields, $order, $limit, $page, $recursive);

string $conditions;

array $fields;

string $order;

int $limit;

int $page;

int $recursive;

For example to retrive all the data from a table you will use following:
PLAIN TEXT
PHP:

$this->set($var, $this->Modelname->findAll());

With the “set function” the $var value will be send to the [...]

Transaction behavior

April 8, 2008

Sample model - note the $actsAs
To change default settings do:
Download code
var $actsAs = array(’transaction’ => array(’keyName’ => ‘value’ ;) );

Model Class:
Download code <?php
class Order extends AppModel
{
var $name = ‘Order’;
var $actsAs = array(‘transaction’);
var $hasMany = array(‘OrderDetail’);
?>
Controller Class:
Download code <?php
class OrderController extends AppController {
var $name = ‘Order’;
var $uses = array(‘Order’);
function checkout() {
if(!empty($this->data)) {
$this->Order->begin(); // Start [...]

Creating Reusable Elements with requestAction

April 8, 2008

Creating reusable elements with requestAction is very simple. At the end, we can even cache the element using the new feature in 1.2.
Start of with a simple controller.
Controller Class:
Download code <?php
class PostsController extends AppController {
var $name = ‘Posts’;
function index() {
$posts = $this->Post->findAll();
if(isset($this->params['requested'])) {
return $posts;
}
$this->set(‘posts’, $posts);
}
}
?>
So, we created the Posts controller and we gave it an [...]

Multiple rules of validation per field in CakePHP 1.2

April 7, 2008

On its 1.1 release, CakePHP only allowed us to define one rule of validation per field. If we needed to specify more than one rule, we either had to use some handy extensions to CakePHP that are available, or achieve multiple validation by using the callback method beforeValidate() in our models. CakePHP 1.2 brings us [...]

CakePHP: Data Validation

March 11, 2008

Data Validation
Creating custom validation rules can help to make sure the data in a Model conforms to the business rules of the application, such as passwords can only be eight characters long, user names can only have letters, etc.
The first step to data [...]

Cake Conventions

March 6, 2008

Filenames

Filenames are underscore. As a general rule, if you have a class MyNiftyClass, then in Cake, its file should be named my_nifty_class.php.
So if you find a
snippet you automatically know that:

If it’s a Controller named [...]

CakePHP: Basic Concept

March 6, 2008

MVC Pattern
The MVC paradigm is a way of breaking an application, or even just a piece of an application’s interface, into three parts: the model, the view, and the controller.
In Cake terms, the Model represents a particular database [...]

CakePHP?

March 6, 2008

What’s CakePHP?
CakePHP is a free open-source rapid development framework for PHP. Its a structure of libraries, classes and run-time infrastructure for programmers creating web applications originally inspired by the Ruby on Rails framework.
Why CakePhp?
CakePHP has several features [...]