Reputation: 21
I have one user model and other is accesscode model. During registration I am using the user model where I have set some validation rules for form data.
On the registration page I have one field which does not belong to the user model i.e. the access code field. I want to validate this field in user model to check whether the code entered by user is present in accesscode table or not and also want to check in third model i.e. useraccesscode for that access code.
How I can do this? I am using CakePHP v1.2.
Thank you
Upvotes: 2
Views: 2342
Reputation: 3828
You can create instances of other models from within any model/controller using one of these two below methods:
If using Cake 1.2:
App::import('model','Attribute');
$attr = new Attribute();
If using Cake 1.1:
loadModel('Attribute');
$attr = new Attribute();
Upvotes: 0
Reputation: 1055
Below example may useful:
App::import('Model', 'Student');
$Student = new Student();
$dataArray = $Student->getDataArray("name like '%".$keword."%'");
Upvotes: 2
Reputation: 475
$validated = $this->User->Accesscode->find('list', array('conditions' => array('Accesscode.name' => $this->data['User']['accesscode'])));
if(count($validated) > 0)
//means that accesscode supplied in the form matches some accesscode in the database
Upvotes: 1