Reputation: 5302
I have this code:
$userObj = ClassRegistry::init('User');
$userObj->contain();
$conditions = "User.studio_id = '".$studioID."' AND User.usergroup_id = 5";
$studioAdmin = $userObj->find($conditions);
The one that is causing the error is this line:
$studioAdmin = $userObj->find($conditions);
When I say error, it does not print anything or any warning of error, it just stops the code below it, I noticed that one because when I try to echo
a code above it, it prints it, but when I try to echo
a code below it, it does not print anything,
What is the problem here. Your help will be greatly appreciated! Thanks! :)
Upvotes: 5
Views: 12887
Reputation: 11853
The better practice way of loading models in components is to go via the controller, and use loadModel()
In your component, set up the initialize()
function initialize($controller, $settings) {
$this->Controller =& $controller;
}
Then in your component function, use loadModel to load the model
$this->Controller->loadModel('Modelname');
$this->Modelname->save($data);
and also for find condition
$users = $this->Modelname->find('all', array(
'conditions' => array(
'User.studio_id' => $studioID,
'User.usergroup_id' => 5
)
));
Upvotes: 2
Reputation: 6780
You should be doing this:
$studioAdmin = $userObj->find('all', array( 'conditions' => $conditions ) );
Do you have PHP error messaging turned on? Did you check your logs to see what the specific error is?
Also, by cake standards, it is better to build your conditions clause this way:
$conditions = array(
"User.studio_id" => $studioID,
"User.usergroup_id" => 5"
);
Upvotes: 0