I have got a maybe silly question - but that's due to my lack of knowledge. I am wondering if I can accomplish the following result.
Controller
class Building extends CI_Controller {
function __construct(){
parent::__construct();
$this->load->model('buildings/buildings_model' , 'buildings');
$is_locked = $this->buildings->_lock;
}
// generic building overview. Includes data like name and location
public function index($obj)
{
// the $obj param is the segment id from router
}
public function details($obj)
{
// here I would get some more specific data
}
public function associates($obj)
{
// list of things that the object is associated
}
}
Model
class buildings_model extends MY_Model{
public $_lock = false;
function __construct() {
parent::__construct();
// example pseudo code
// db query select lock from obj where id = 1 for example
// if lock == 1 { $this->_lock = TRUE; }
}
}
And now the question.. I assigned a global variable public $_lock = false;
in the model
so it's accessible in every scope of the controller
.
But each time I access the views
, the model constructor
each time makes a query to check if Object is locked. Generally I need a global flag if the building is locked - but generated once not every page view.