我的控制器是這樣的:如何在功能擴展控制器中獲取數據?
<?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是這樣的:
<?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']);
}
}
?>
我的索引視圖是這樣的:
<?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
看來它不能調用get_notification功能EX控制器
我把功能get_notification(EX Controller)
在所有控制器
讀取任何解決方案來解決我的問題呢?
凡被定義'$ data'? – meda
@meda,沒有'$ data',但是'$ this-> data'。我想在函數get_notification(EX_Controller)中得到'$ this-> data ['notification']'和'$ this-> data ['count_notification']'。然後將其發送到index_view。 –
是的,但我沒有看到你的代碼中你聲明瞭那個屬性,它應該是public public data;' – meda