2

My controller is like this:

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

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

When executed, there exist error :

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

It seems it can not call get_notification function in EX Controller

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

Any solution to solve my problem?

moses toh
  • 10,726
  • 57
  • 212
  • 388

1 Answers1

1

The solution to this problem is to just use this:

$this->load->model('notification_model'); 
$this->get_notification();
meda
  • 44,540
  • 14
  • 88
  • 122
  • 1
    I try it without `public $data;`. It's working. So, I just use this: `$this->load->model('notification_model'); $this->get_notification();` – moses toh Jul 04 '16 at 05:19
  • Just use this: `$this->load->model('notification_model'); $this->get_notification();`. Without `$data`, it's working. I had update your answer – moses toh Jul 04 '16 at 06:48
  • I need you help. Look here : http://stackoverflow.com/questions/38189488/how-to-remove-single-quotes-in-prepare-statement – moses toh Jul 05 '16 at 01:07