Welcome Guest, Not a member yet? Register   Sign In
Extending BaseController gives error
#1

(This post was last modified: 09-03-2019, 06:37 AM by Ambroz.)

Hi.
I'm trying to use some code from CI 3 and got a error, where I can't use the provided variables to load views by template.
The error is just the site isn't loading.

This is the code I would like to use in CI 4:
PHP Code:
<?php
class GE_Controller extends CI_Controller
{
    protected 
$_viewData = [];
    protected 
$loginData '';

    
/**
    * ste footer and header
    * @param none
    * @return constructor
    **/
    
function __construct()
    {
        
parent::__construct();

        
//load header
        
$this->_viewData['message'] = $this->session->flashdata('message');
        
$this->_viewData['header'] = $this->load->view('parts/header'$this->_viewDatatrue);
    }
}

class 
MY_Controller extends GE_Controller
{
    
/**
    * ste footer and header
    * @param none
    * @return constructor
    **/
    
function __construct()
    {
        
parent::__construct();

        
$uri $_SERVER['REQUEST_URI'];
        
$s $this->session->get_userdata();

        
$ok = isset($s['user']);

        if(
$ok)
        {
            
$this->loginData $s['user'];
            
$this->_viewData['loginData'] = $this->loginData;
        }

        
$this->_viewData['footer'] = $this->load->view('parts/footer'$this->_viewDatatrue);

    }


I've used the _viewData to load views by the template.
One of my old, I mean CI 3, controllers:
PHP Code:
defined('BASEPATH') OR exit('No direct script access allowed');

class 
Main extends MY_Controller {

    public function 
index(){

            
$this->_viewData['logo'] = $this->load->view('logo'$this->_viewDatatrue);
            
$this->_viewData['content'] = $this->load->view('login'$this->_viewDatatrue);
            
$this->load->view('parts/template'$this->_viewData);
        }
    }


The template code:
PHP Code:
<?=$header?>


<? if(!empty($logo)):?>
<?=$logo ?>

<?php
//show menu if any
if(isset($menu) && !empty($menu)) echo $menu?>

<?php
//show message if any
if (isset($message) && !empty($message))
    echo 
"<div class='uk-alert'>".$message."</div>";?>
<? if(!empty($content)): ?>

    <?=$content ;?>
<? endif; ?>

<?=$footer?>

I really like this method of constructing the site, so could you help me make it work?
Hope you will help me Smile . Thanks a lot.
Reply


Messages In This Thread
Extending BaseController gives error - by Ambroz - 09-03-2019, 05:44 AM



Theme © iAndrew 2016 - Forum software by © MyBB