Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cakephp ClassRegistry::init

Tags:

php

cakephp

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! :)

like image 822
PinoyStackOverflower Avatar asked Nov 03 '22 23:11

PinoyStackOverflower


1 Answers

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
   )
));
like image 64
liyakat Avatar answered Nov 09 '22 06:11

liyakat