Changing CakePHP's Model useTable on the Fly

Posted on 11/02/2010 at 05:12 pm by Kevin Wentworth
Viewed 18,321 times | 0 comments

I finally found an answer to/solution to something I've never been able to get around in CakePHP before: dynamically changing/setting the useTable value in a model.  You can't just say $this->CakePHPModel->useTable = 'cakephp_table_name';  Instead you have to use the following function:

Setting CakePHP Model useTable Dynamically

  1. $this->CakePHPModelName->setSource('table_name');

Thanks to Give Me Cake for sharing.  This will work from the controller or the model.  I'm using it to build an all-purpose importer model.

-Kevin Wentworth

Bookmark and Share

Tags for Changing CakePHP's Model useTable on the Fly

Cakephp | Web Programming | Mysql | Database | Example | Tutorial

Comments for this Posting

No comments. Be the first to post a reply.

Sorry, comments are closed for this posting.

Please Email Kevin if you have any questions. Thanks!

Meet Site Avenger - Hosted Content Management System

Powered By: Site Avenger | Site Production: Saco Design