Welcome Guest, Not a member yet? Register   Sign In
Checking if application is closed/open?
#1

[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.
#2

[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.




Theme © iAndrew 2016 - Forum software by © MyBB