Welcome Guest, Not a member yet? Register   Sign In
How to autoload sitewide variables
#11

[eluser]davidbehler[/eluser]
Works fine for me. Using a fresh CI 1.7.2 install I did this:
Create a new file application/libraries/MY_Controller.php with this content:
Code:
<?php

class MY_Controller extends Controller {

    function MY_Controller()
    {
        parent::Controller();    
    }
    
    function _output($output)
    {
        echo str_replace('background-color: #fff;', 'background-color: blue;', $output);
    }
}

Edit application/controllers/welcome.php and made it extend MY_Controller instead of Controller:
Code:
<?php

class Welcome extends MY_Controller {

    function Welcome()
    {
        parent::Controller();    
    }
    
    function index()
    {
        $this->load->view('welcome_message');
    }
}

Going to index.php/welcome I see the normal welcome dummy page with a blue background instead of the white one.

Make sure you have set the subclass prefix correctly in application/config/config.php:
Code:
$config['subclass_prefix'] = 'MY_';

Maybe you can get it to work now Smile
#12

[eluser]Christophe28[/eluser]
Hi,

Thank you, you brought me a step further. I get it to load the requested page, but just one last (probably silly) question. How can I attach variables at the $output. You echo the $output, and 'str_replace' something, but with which function you can attach variables ... or how should you do this?

Many, many thanks!!!

Christophe




Theme © iAndrew 2016 - Forum software by © MyBB