最近我开始使用TinyMVC编写了一个简单的菜单模型,我对那些正在使用它或以前使用过的人有几个问题。1. 对于以下代码,我应该将其保留为模型还是插件?2.我应该如何在视图中实现它并在每个需要的页面上使用它而不破坏mvc的想法并且不为每个控制器一次又一次地重写?3. 代码有什么改进吗?4.需要mysql表吗?
<?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;
}
}