dongpao9165 2016-04-02 16:57
浏览 11

Codeigniter共享变量

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.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度
    • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测