Data available for all views in codeigniter

后端 未结 8 1258
日久生厌
日久生厌 2020-12-09 10:56

I have a variable, contaning data that should be present in the entire site. Instead of passing this data to each view of each controller, I was wondering if there is a way

8条回答
  •  北荒
    北荒 (楼主)
    2020-12-09 11:25

    You could override the view loader with a MY_loader. I use it on a legacy system to add csrf tokens to the page where some of the forms in views don't use the builtin form generator. This way you don't have to retrospectively change all your controllers to call MY_Controller from CI_Controller.

    Save the below as application/core/MY_Loader.php

    security->get_csrf_hash();
            return $this->_ci_load(array('_ci_view' => $view, '_ci_vars' => $this->_ci_prepare_view_vars($vars), '_ci_return' => $return));
        }
    }
    

提交回复
热议问题