• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Function inside the constructors are not working Any Help

#1
For example my constructor is given below and the following is not working if it is in the constructor . But it works outside the constructor

PHP Code:
public function _construct()
{
    
$this->session = \Config\Services::session();
    
$menu = new MenuModel();  
    
$data['menu_list'] = $menu->get_menu_list(session()->role_id);   
    echo 
view('common/menu',$data);

Reply

#2
Hi, you need to put it inside a initController instead.

PHP Code:
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger)
{
    
// Do Not Edit This Line
    
parent::initController($request$response$logger);

    
$this->session = \Config\Services::session();
    
$menu = new MenuModel();  
    
$data['menu_list'] = $menu->get_menu_list(session()->role_id);   
    echo 
view('common/menu',$data);

Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.