Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/262937-tinymvc-model-plugin/
Share on other sites

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.

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.. ? :)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.