You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Derek Jones edited this page Jul 5, 2012
·
6 revisions
One of the motives I created the article "Virtuals formats hooks for CodeIgniter" was for creating the feature of this article. Imagine you have some variables you wanna to load into your scripts but this values changes depending from data manipulated from the serverside (in our case a CodeIgniter application), and we don’t like to put this variables between [removed][removed] tags, because this is ugly, and a non good programming practice as the YSlow Firefox plugin rule says: Yahoo Developers. So what I do is to build a new Controller called "configs" which in the constructor builds me to variables I need for my ExtJS based application. This is the code:
class Configs extends Controller{
functionConfigs()
{
parent::Controller();
$this->load->helper('url');
$this->globals['base_url']=base_url();
$this->globals['scripts_base']=$this->globals['base_url'].'system/public/scripts/';
}
functionindex()
{
echo"This hosts dynamics virtual files for global vars";
}
functionglobal_vars($archive)
{
switch($this->router->format)
{
case"js": //If you are asking for a javascript fileforeach($this->$archiveas$key_name=>$key_value)
echo"var $key_name='$key_value';\n";
}
}
}
So in your view file you could put:
[removed][removed] and keep the HTML code optimized and clean, and this fake script file adapts to the server configuration because is in fact a server script. It's very useful to those like me who develops application with javascript libraries like ExtJS, JQuery, Dojo and his friends ;)…
Thanks to anybody who reads this article, I hope it would be useful for you. I will thanks feedback to [email=eliecerhdz@gmail.com]me[/email].
Greetings, Eliecer (EliuX) Hdz. Garbey.