如何在功能扩展控制器中获取数据? [英] How to get data in function extend controller?

查看:34
本文介绍了如何在功能扩展控制器中获取数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的控制器是这样的:

<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Dashboard extends EX_Controller
{
    public function __construct()
    {
        parent::__construct();
    }

    public function index()
    {
        $this->data['news'] = $this->dashboard_model->get_news();
        $this->load->view('dashboard/index_view', $this->data);
    }

我的 EX_Controller 是这样的:

My EX_Controller is like this :

<?php
class EX_Controller extends CI_Controller
{
    public $data;
    public function __construct()
    {
        parent::__construct();

        $this->load->model('notification_model');
        $this->get_notification();
    }

    public function get_notification()
    {
        $session = $this->session->userdata('login');
        $this->data['notification'] = $this->notification_model->get($session);
        $this->data['count_notification'] = $this->notification_model->get_count_notification($session['customer_id']);
    }
}
?>

我的索引视图是这样的:

My index view is like this :

<?php
    foreach ($notification as $value) {
?>
        <li>
        <?php
            echo '<a href='.base_url().'notification/notif/'.$value['notification_id'].'>';
        ?>
                <span class="time">
                <?php 
                    echo time_elapsed($value['notification_created_date']); 
                ?>
                </span>
                <span class="details">
                    <span class="label label-sm label-icon label-info">
                        <i class="fa fa-bookmark"></i>
                    </span> <?php echo $value['notification_message']; ?>
                </span>
            </a>
        </li>
<?php
    }
?> 

执行时出现错误:

Message:  Undefined variable: count_notification
Message:  Undefined variable: notification

好像不能在EX Controller中调用get_notification函数

It seems it can not call get_notification function in EX Controller

我输入了函数 get_notification(EX Controller) 以便在所有控制器中读取

I put in function get_notification(EX Controller) to be read in all controllers

有什么解决方案可以解决我的问题?

Any solution to solve my problem?

推荐答案

解决这个问题的方法就是这样:

The solution to this problem is to just use this:

$this->load->model('notification_model'); 
$this->get_notification();

这篇关于如何在功能扩展控制器中获取数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆