CodeIgniter Forums
Checking if application is closed/open? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Checking if application is closed/open? (/thread-9281.html)



Checking if application is closed/open? - El Forum - 06-19-2008

[eluser]EEssam[/eluser]
Hello,

I'm lost a little bit. So here's one of the issues I'm currently facing.

I've an autoloaded model to get the application settings from DB (See this please).

Now one of my settings is called "appactive" and I need to check if the app is active every time the app is requested, so I decided to create another model that I'll autoload and call it Init_model where I have something like:

// Check if the site is closed
if (!$this->settings_model->options['appactive'])
{
$this->load->view($this->settings_model->options['style'] . '/closed', $this->data);
}

It's not working and I'm not very interested in finding why it's not working because it's not good to call a view file from a model anyway.

If I place the previously mentioned code in a controller it works but it's not logical to repeat it in all my controllers!

What are the (good) solutions for this?

Please help.


Checking if application is closed/open? - El Forum - 06-21-2008

[eluser]Grahack[/eluser]
You can create a base controller with common vars and functions. All your controllers will inherit from it.

In application/libraries/MY_Controller.php
Code:
<?php
Class MY_Controller extends Controller {

    var $common_var;
    
    function MY_Controller()
    {
        parent::Controller();
    }
    
    function mult( $n1, $n2 )
    {
        return $n1 * $n2;
    }
}

In application/controllers/product.php
Code:
<?php

class Product extends MY_Controller {

    function Product()
    {
        parent::MY_Controller();
    }
    // ...
    // here you can use $this->mult()
}

Have a try and keep us updated.