Problem with altering model attributes in controller
Posted
by SpawnCxy
on Stack Overflow
See other posts from Stack Overflow
or by SpawnCxy
Published on 2010-04-26T02:45:48Z
Indexed on
2010/04/26
2:53 UTC
Read the original article
Hit count: 229
cakephp
|model-attribute
Hi all,
Today I've got a problem when I tried using following code to alter the model attribute in the controller
function userlist($trigger = 1)
{
if($trigger == 1)
{
$this->User->useTable = 'betausers'; //'betausers' is completely the same structure as table 'users'
}
$users = $this->User->find('all');
debug($users);
}
And the model file is
class User extends AppModel
{
var $name = "User";
//var $useTable = 'betausers';
function beforeFind() //only for debug
{
debug($this->useTable);
}
}
The debug message in the model showed the userTable
attribute had been changed to betausers
.And It was supposed to show all records in table betausers
.However,I still got the data in the users
,which quite confused me.And I hope someone can show me some directions to solve this problem.
Regards
© Stack Overflow or respective owner