Give Me Cake

CakePHP Baking, Internet Marketing, SEO, Design and more

Changing Model’s useTable from Controller

Posted on | August 8, 2010 | 3 Comments

I was struck trying to get the controller to change the table of a model for a while. It turns out that

$this->Payment->useTable = “payment_archives”;

doesn’t work..

Instead I have to use:

$this->Payment->setSource(“payment_archives”);

It seems that useTable is not referenced to when deciding which table to use.

Comments

3 Responses to “Changing Model’s useTable from Controller”

  1. dogmatic69
    August 9th, 2010 @ 4:58 pm

    That is not the way you should be doing things imo. if you want to use a different table $uses is the way to go.

    If you want to use a different model for one method in your controller, loadModel() is what you want.

    Having the code randomly switching db’s will not be fun when you need to debug in a few weeks/months time.

  2. givemecake
    August 9th, 2010 @ 9:39 pm

    I am referring to change the table used by the model in the controller, not loading a different model. Sure you can use the var $uses to setup the table in the codes. But to swap the table used by model temporary, use setSource

  3. mainelydesign
    November 3rd, 2010 @ 4:58 am

    Thanks, this is just what I needed. I was trying to figure out how to do this.

Leave a Reply





  • Give me Cake?

    Givemecake.dev-work.com a collection of web application development tips, tutorials and resources.
  • See Your Ads Here

  • See Your Ads Here

  • Meta