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: [...]
Archive for the ‘CakePHP’ Category
Retrieving data in CakePHP
April 23, 2008Transaction behavior
April 8, 2008Sample 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 { [...]
Creating Reusable Elements with requestAction
April 8, 2008Creating 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); } [...]
Multiple rules of validation per field in CakePHP 1.2
April 7, 2008On 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, 2008Data 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 validation is creating the validation rules in the Model. To [...]
Cake Conventions
March 6, 2008Filenames 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 KissesAndHugsController, then its filename must be kisses_and_hugs_controller.php(notice _controller in the filename) If it’s a Model named OptionValue, [...]
CakePHP: Basic Concept
March 6, 2008MVC 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 table/record, and it’s relationships to other tables and records. Models also contain data validation rules, [...]
CakePHP?
March 6, 2008What’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 that make it a great choice as a framework for developing applications swiftly and with [...]