bogdaniel Posted May 22, 2012 Share Posted May 22, 2012 recently i started working with TinyMVC, wrote a simple menu model and i have few questions for those who are using it .. or used before. 1. For the following code should i keep it as Model or as a Plugin? 2. How should i implement it in the view and use it on every page that is required without breaking the ideea of mvc and without rewriting again and again for each controller? 3. Any improvements to the code? 4. Need the mysql tables ? <?php class Menu_Model extends TinyMVC_Model { public function __construct() { parent::__construct(); } public function listMenu() { return $this->db->query_all("SELECT * FROM menu_links WHERE is_deleted = 0 ORDER BY position"); } public function listCategorys($menuLinkId) { return $this->db->query_all("SELECT * FROM menu_subcategorys WHERE menuLinkId = ? AND is_deleted = 0 ORDER BY position", array($menuLinkId)); } public function buildMenu() { $this->listMenu = $this->listMenu(); foreach($this->listMenu as $this->listMenuKey => $this->listMenuValue) { $this->listCategorys = $this->listCategorys($this->listMenuValue['menuLinkId']); if(!empty($this->listCategorys)) $this->listMenu[$this->listMenuKey]['child'] = $this->listCategorys; } return $this->listMenu; } } Quote Link to comment https://forums.phpfreaks.com/topic/262937-tinymvc-model-plugin/ Share on other sites More sharing options...
smoseley Posted May 22, 2012 Share Posted May 22, 2012 3. Any improvements to the code? Pull the entire menu in one query, using LEFT JOINs. It will improve performance significantly. Also, consider revising the schema so "links" and "categories" are both stored in the same table of "menu_elements" - a self-referencing table with a "type" column defining what type of menu item it is. Quote Link to comment https://forums.phpfreaks.com/topic/262937-tinymvc-model-plugin/#findComment-1347680 Share on other sites More sharing options...
bogdaniel Posted May 22, 2012 Author Share Posted May 22, 2012 3. Any improvements to the code? Pull the entire menu in one query, using LEFT JOINs. It will improve performance significantly. Also, consider revising the schema so "links" and "categories" are both stored in the same table of "menu_elements" - a self-referencing table with a "type" column defining what type of menu item it is. i'll do that :-) what about the view part any sugestions.. ? Quote Link to comment https://forums.phpfreaks.com/topic/262937-tinymvc-model-plugin/#findComment-1347689 Share on other sites More sharing options...
smoseley Posted May 23, 2012 Share Posted May 23, 2012 I know nothing about TinyMVC, so can't help with the details there... I offered all the help I can already. Sorry! Quote Link to comment https://forums.phpfreaks.com/topic/262937-tinymvc-model-plugin/#findComment-1347857 Share on other sites More sharing options...
Mahngiel Posted May 24, 2012 Share Posted May 24, 2012 You should use it as a library / plugin. Quote Link to comment https://forums.phpfreaks.com/topic/262937-tinymvc-model-plugin/#findComment-1348298 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.