MainelyDesign.com Blog

Changing CakePHP's Model useTable on the Fly

Posted on 11/02/2010 at 05:12 pm by Kevin Wentworth
Viewed 2,767 times | 1 comment

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.

Cheers,
-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

Posted by Satyen Rudra

on 29/12/11

Hello,

Nice code. many many thanks.

Regards,
satyen

Leave a Comment

Post a Reply

Will not be posted or used in any way.

We'll link back to your site if you want.

No links or formatting allowed.

Meet Site Avenger - Hosted Content Management System

Powered By: Site Avenger | Site Production: Saco Design