Viewed   57 times

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?

 Answers

1

The solution to this problem is to just use this:

$this->load->model('notification_model'); 
$this->get_notification();
Friday, December 16, 2022
4

Hm, understand. As I see the subquery's source code in line 27, it wants to call _compile_select or get_compiled_select. If you can check in CI's DB_active_rec.php the _compile_select is protected so you can't access from Subquery (it isn't subclass of db).

Possible solution: _compile_select() should public or class Subquery should be extend of CI's db class. I think you should report this to author of Subquery.

Or you can extend the CI's db class :)

Sorry - I want to write it as a comment.

Sunday, December 18, 2022
 
ghazi
 
3

Try this code it might help you :

Here dashboard is the name of controller

//this will route as localhost/appFolder/admin/index
  $route['admin'] = 'dashboard'; // for your index page

//this will route as localhost/appFolder/admin/method_name
 $route['admin/(:any)'] = 'dashboard/$1';

//this will route as localhost/appFolder/admin/method_name/param1
$route['admin/(:any)/(:any)'] = 'dashboard/$1/$2';

Link the route Like

// for your index page
<a href="<?php echo base_url('admin/index'); ?>"></a>

// for your other pages
<a href="<?php echo base_url('admin/method_name'); ?>"></a>

To link the other controller defined just like

 <a href="<?php echo base_url('otherControllerName/method_name'); ?>"></a>
Sunday, September 4, 2022
 
2

Of course your logs return undefined : you log before the request is done. The problem isn't scope but asynchronicity.

http.request is asynchronous, that's why it takes a callback as parameter. Do what you have to do in the callback (the one you pass to response.end):

callback = function(response) {

  response.on('data', function (chunk) {
    str += chunk;
  });

  response.on('end', function () {
    console.log(req.data);
    console.log(str);
    // your code here if you want to use the results !
  });
}

var req = http.request(options, callback).end();
Thursday, September 22, 2022
 
3

Υou can write it that way

Item::find($request->item_id)->update(['onloan' => 1,]);

Create you can also do it

 Transaction::create([$request->all()]);
Sunday, September 11, 2022
 
chesucr
 
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :