View Loader for CodeIgniter
Open Issues: 0
- php: >=5.3.0
This package is not auto-updated.
Last update: 2023-03-27 19:35:51 UTC
View Loader for CodeIgniter helps to load the view, and inject language strings into the view.
How to use
Initiate the object
If installed with composer, include the autoloader and initiate the object, with the CodeIgniter object passed in. Since views should be loaded only in the controller, it is safe to pass $this
$viewLoader = new \SlaxWeb\ViewLoader\Load($this);
Load the view
To load the view
If you want to include a header and footer view, those must be set before
$viewLoader->setHeaderView("header/file"); $viewLoader->setFooterView("footer/file"); $viewLoader->loadView("view/file", $dataArray);
Of course you can set both, or either of them. If you have loaded the header and view, but you want to exclude them for the view that you want to load, pass false, as the third parameter in loadView
$viewLoader->loadView("view/file", $dataArray, false);
View loader provides a possibility to pass your language strings into the view. But so you don't pass all of them, it is limited by prefixes in the key of the language array.
$this->lang->load("languageFile"); $viewLoader->setLanguageStrings("prefix_"); $viewLoader->loadView("view/file", $dataArray);
This takes all the language strings which have their keys prefixed with "prefix_" and injects them into the view data to be used as regular variables. So $lang["prefix_myString"] becomes $myString in the view.