
Search In
Lets say there are two models named as User and Post. A User hasMany Post, so in our User model we have a relation like this :-
class User extends AppModel{
var $name = ‘User’;
var $hasMany = array(‘Post’=>array(‘foreignKey’=>’user_id
If we have to many tables in our project and we have many association between them. So whenever we use one of the model in our controller the other model which are associated with it , automatically get attached with user data .
Sometime we don'
Hi Reader's,
Welcome to FindNerd,today we are going to discuss bindModel and unbindModel function in CakePHP 2.X.
If we are making any web application in CakePHP then sometimes we have to use bindModel and unbindModel at a runtime. So CakePHP pr
bindModel and unbindModel:
bindModel() function is used to create association between models when needed and unbindModel() function is used to destroy the created association when it is no longer required. Association are used when we need data from
How use auth login in different model in cakephp
public $components = array('Session', 'Cookie',
'Auth' => array(
'authenticate' => array('Form' => array( 'userModel' => 'Admin',
'fields' => arr
Hi
If you want a condition where you can load another model inside you model. you can do as I code, see the example below
App::import('Model', 'MyModel'); $my_model = new MyModel();
Or you can write
$this->SomeModel->MyModel;
if you hav
Hello Readers;
If you want to remove the validation in cakephp from the Model dynamically then use the below one line code.
$this->validator()->remove('username');
The above validation completely remove all rules for a field.(Here we use us
By using Containable Behavior we can filter model assoceation. we use 'Containable' keyword for use contain
we add this property in model
class User extends AppModel {
public $actsAs = array('Containable');
}
and we can use this on fly also
Hi if you want a condition where you want to load another model inside you model.
you can do as I code follow
App::import('Model', 'MyModel');
$my_model = new MyModel();
Or you can write
$this->SomeModel->MyModel
if you have already this
Updation in CakePHP is basically based on knowing the primary key(Id) of the records one wants to change/edit.
You can update a field in CakePhp by two ways:-
a)By using saveField method
$this->ModelName->id=$id;
$this->ModelName->