doujiao3998 2013-11-05 10:58
浏览 48
已采纳

最佳结构Codeigniter,恒定的顶级菜单

Maybe a HMVC structure would have been best when I look back.

I load the following views in every controller.

$this->load->view('header');
$this->load->view('DEPENDING');
$this->load->view('header');

In my header-view I have a menu which I show Home | Inbox | Contact us and so on. Now I want to load how many new messages you have like this Home | Inbox (4) | Contact. If Im not wrong the 4 most be loaded thorugh a query every time. Which I then need to include a call to a model in EVERY controller. Like e.g.

$inbox['new_messages'] = $this->Call_the_model->get_new_messages(); // user id go through session

$this->load->view('header', $inbox);
$this->load->view('DEPENDING');
$this->load->view('header');

Am I right? Is there simple solution for me to use - even if Im not using HMVC?

  • 写回答

1条回答 默认 最新

  • dongqiaozhe5070 2013-11-05 13:00
    关注

    One of the ideas is -

    http://ellislab.com/codeigniter/user-guide/general/core_classes.html

    class MY_Controller extends CI_Controller {
        function __construct()
        {
            parent::__construct();
            //load your model
            $inbox_new_messages = $this->Call_the_model->get_new_messages();
            //save in session
            $this->session->set_userdata('sess_inbox_new_messages', $inbox_new_messages);
        }
    
    }
    

    then just extend your controllers with new MY_Controllers and

    class Welcome extends MY_Controller {
    
        function __construct()
        {
            parent::__construct();
        }
    
     }
    

    in your view files - check if that session variable is set and display the number. Hope that helps.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 stm32流水灯+呼吸灯+外部中断按键
  • ¥15 将二维数组,按照假设的规定,如0/1/0 == "4",把对应列位置写成一个字符并打印输出该字符
  • ¥15 NX MCD仿真与博途通讯不了啥情况
  • ¥15 win11家庭中文版安装docker遇到Hyper-V启用失败解决办法整理
  • ¥15 gradio的web端页面格式不对的问题
  • ¥15 求大家看看Nonce如何配置
  • ¥15 Matlab怎么求解含参的二重积分?
  • ¥15 苹果手机突然连不上wifi了?
  • ¥15 cgictest.cgi文件无法访问
  • ¥20 删除和修改功能无法调用