TinyMVC Model / Plugin如何实现?

时间:2012-05-22 13:29:39

标签: php mysql

最近我开始与TinyMVC合作编写了一个简单的菜单模型,对于那些使用它的人来说,我几乎没有问题。 1.对于以下代码,我应该将其保留为模型还是插件? 2.我应该如何在视图中实现它并在每个页面上使用它而不破坏mvc的ideea并且不对每个控制器一次又一次地重写? 3.对代码的任何改进? 4.需要mysql表吗?

Code Here

<?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;
    }
}

0 个答案:

没有答案