Changing model's table from the controller

For one reason, or another you might wish to change your Model’s table on the fly…

It would seem that it should be quite easy to do with:

$this->Company->useTable = ‘another_company_table’;

…but it’s not going to work…

Instead, in your controller, use:

$this->Company->table = ‘another_company_table’;

I haven’t checked to see why this works the way it does, so if someone has an explanation, I’ll gladly update the post with your insight.

P.S. Phally pointed out that it is better is use the wrapper for setting the table variable (always better than setting vars directly), like so: $this->Company->setSource(‘another_company_table’);

Related Posts