son.of.the.morning Posted January 2, 2012 Share Posted January 2, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/254210-creating-a-single-model-for-multiple-tables/ Share on other sites More sharing options...
ignace Posted January 2, 2012 Share Posted January 2, 2012 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; } } Quote Link to comment https://forums.phpfreaks.com/topic/254210-creating-a-single-model-for-multiple-tables/#findComment-1303398 Share on other sites More sharing options...
son.of.the.morning Posted January 2, 2012 Author Share Posted January 2, 2012 Thanks man. I shall have a crack at it soon and let you know how i get on. Quote Link to comment https://forums.phpfreaks.com/topic/254210-creating-a-single-model-for-multiple-tables/#findComment-1303423 Share on other sites More sharing options...
jcombs_31 Posted January 7, 2012 Share Posted January 7, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/254210-creating-a-single-model-for-multiple-tables/#findComment-1305313 Share on other sites More sharing options...
sKunKbad Posted January 10, 2012 Share Posted January 10, 2012 What happens when you want to do an sql join? Quote Link to comment https://forums.phpfreaks.com/topic/254210-creating-a-single-model-for-multiple-tables/#findComment-1305983 Share on other sites More sharing options...
jcombs_31 Posted January 10, 2012 Share Posted January 10, 2012 What happens when you want to do an sql join? CakePHP does the magic on the backend if models are properly linked. http://book.cakephp.org/1.3/en/view/1017/Retrieving-Your-Data Quote Link to comment https://forums.phpfreaks.com/topic/254210-creating-a-single-model-for-multiple-tables/#findComment-1306075 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.