Welcome Guest, Not a member yet? Register   Sign In
Function inside the constructors are not working Any Help
#1

(This post was last modified: 08-21-2020, 01:24 PM by jreklund.)

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




Theme © iAndrew 2016 - Forum software by © MyBB