Jump to content

creating a single model for multiple tables


son.of.the.morning

Recommended Posts

I am using cakephp to create a cms as i have properly said in numerous posts lol. I am totally new to MVC so it's quite a head fuck at the moment. I have followed a tutorial on how to create a blog using cakephp and from what i have so far i understand how to create a model for one table. In my cms i have multiple tables when i want to be able to interact with on a single page. I really don't no were to start with it at all so if anyone can give me a little help or a push in the right direction it would be much appreciated.

 

Thanks 

Create a model for each table. This makes sure that you can benefit of all what the framework has to offer (Like the Associations in CakePHP). Create a new model that will sit on top of these table models.

 

class FridgeController extends AppController {
    public function analyseMyFridgeAndReturnPossibleRecipes() {
        $recipes = $this->FridgeRepository->findPossibleRecipesByFridgeContents();
        return $recipes;
    }
}

If models are properly linked you can make references from another controller.  Like $this->Pet->Dog->function()

 

You can also use $uses. This would be typical of something like a dashboard controller that you need to access multiple models.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.