For the cakePhp beginners there are some useful things always to remember for developing application or to learn make easy and fast. There are some good examples of code to get the form submitted data, load a model in the controller and create own mode script.
How to get the form posted data in the controller methods?
// THIS IS A CONTROLLER METHOD
public function fetFormSubmittedData($data){
// TO GET ALL THE FORM DATA
$this->request->data
// FOR INDIVIDUAL FIELD DATA
$this->request->['fieldname1'];
$this->request->['fieldname2'];
$this->request->['fieldname3'];
}
How to load model in the controller?
public function loadUserModel()
{
// THIS IS THE CODE TO LOAD USER MODEL
$this->loadModel('User');
// THIS IS A QUERY DATA FROM THE USER MODEL
$USERS = $this->User->find('all',array('conditions',array('country','USA')));
}
To run your code successfully do Authentication in the filter method of the controller class.
// CONTROLLER FILTER
public function beforeFilter()
{
parent::beforeFilter();
// AUTHENTICATION AND AUTHORIZATION FOR APPLICATION
$this->Auth->allow('loadUserModel');
}
How to code to create your own MODEL to query data from a database table?
first create the file with the name of the model that you want user like for cities mode file name should be 'Cities.php'
// LOAD THE APPLICATION MODEL CLASS
App::uses('AppModel', 'Model');
// CTEATE THE CLASS WITH THE SAME NAME THE MODEL FILE CREATED
class Cities extends AppModel {
// DEFINE NAME TO ACCESS THE MODEL
public $name = "Cities";
// DEFINE DATABASE TABLE NAME ACCESS THROUGH WITH THIS MODEL
public $useTable = "cities_usa";
// THIS IS MODEL BEHAVIOR TO FIND FILER AND LIMIT THE DATA
public $actsAs = array('Containable');
}