Welcome Guest, Not a member yet? Register   Sign In
Custom url variable for the resources?
#1

[eluser]tnathos[/eluser]
hi in my app use severals folders for locate css, imgs and js.

I use always the route whit the variable <?=base_url()?> for locate the resources. examples..

Code:
<link href="<?=base_url()?>system/files/grid/css/style.css" rel="stylesheet" type="text/css" />
<link href="<?=base_url()?>system/files/grid/css/flexigrid.css" rel="stylesheet" type="text/css" />
<link type="text/css" href="<?=base_url()?>system/files/jsc/themes/base/ui.all.css" rel="stylesheet" />
<link rel="stylesheet" href="<?=base_url()?>system/files/styleMenu.css" type="text/css" />
<link rel="stylesheet" href="<?=base_url()?>system/files/styles.css" type="text/css" />
<link rel="stylesheet" href="<?=base_url()?>system/files/stylesUser.css" type="text/css" />

I think if i can make other variables for out the locate complete and reduce the code in the view, and put this variable in a file the config but i dont know in where can. i like this example.

$jqueryfolder = "<?=base_url()?>system/files/jsc/";
$cssfolder = "<?=base_url()?>system/files/css/";

and use...
<link href="<?=cssfolder()?>style.css" rel="stylesheet" type="text/css" />


thanks for the advance
#2

[eluser]Twisted1919[/eluser]
In your config.php file you can add your custom config if you want , as folows :
$config['site_css'] = $config['base_url'].'css/';
Then , you extend the Controller with MY_Controller and load that variable in it as follows :
Code:
Class MY_Controller extends Controller{

function MY_Controller()
   {
   $things = array('css_folder'=>$this->config->item('site_css'));
   $this->load->vars($things);
   }

}
Then , in any of your views you can simply type <?=$site_css;?> and will give you the path that you have in your config.php file .
For example, in your header you can load the style.css like :
<link rel="stylesheet" href="<?=$css_folder;?>style.css" type="text/css" />
I think you got the ideea .
Anyway, keeping your assets in your application directory, is not a good and practical ideea, keep them in your site root .
#3

[eluser]tnathos[/eluser]
thanks!! this perfect.. and the css i keep in the site root not in the application directory, but thanks for the coment.

Now i have a dude in other post i see what i can handled this vars whit a constants.. in constants.php, this a good practice or better in config?
#4

[eluser]Colin Williams[/eluser]
I think the simplest thing to do is create config entries for all these paths, then just do config_item('css_path') etc. in your views
#5

[eluser]Twisted1919[/eluser]
[quote author="tnathos" date="1255149776"]
Now i have a dude in other post i see what i can handled this vars whit a constants.. in constants.php, this a good practice or better in config?[/quote]

I use the config , because , i save all these config items to database , then i overwrite them with $this->config->set_item('item','new value');
This is the way that i found to be more convenient, like this i can set some default values for the project, then when building the backend , the client will have the oportunity to overwrite these settings without changing the config.php file ....

So i would say to use the config instead of constants .
#6

[eluser]tnathos[/eluser]
tnahks.. newbie question..

1. My:controller is a new controller what i create in folder application/controllers?
2. how i create severals entries in My_controller this?

function MY_Controller()
{
$things = array('css_folder'=>$this->config->item('site_css'),
'js_folder'=>$this->config->item('site_js') );
$this->load->vars($things);
}

}
#7

[eluser]Twisted1919[/eluser]
1.MY_Controller.php is the filename that you must create in your /system/application/libraries
2.Then, after you will do this , the file must contain :
Code:
class MY_Controller extends Controller{

function MY_Controller(){
//do stuff here, like pre-checks or loading things
//this is the class contructor ...
}

}
3.Now, when creating a new controller in your /controllers folder, that controller MUST extend MY_Controller NOT Controller, that is if you want to inherit all the functions from MY_Controller and i think you want once you built it Smile

For more info, you can see the user guide on this , it's very well written and i'm sure you will find your answers there if i wasn't clear enough Smile
#8

[eluser]tnathos[/eluser]
thanks Smile
#9

[eluser]tnathos[/eluser]
mmm i make the controller in libraries and all.. but showme this error..

A PHP Error was encountered

Severity: Notice

Message: Undefined variable: css_folder

Filename: home/header.php

Line Number: 1
#10

[eluser]tnathos[/eluser]
mmm doesnt works... pls any.. i put make this..


MY_Controller
<?php
/**
* Extension to CI Controller
*
* This controller intercept allows
* ...
*
* @author yourname
* @package yourpackagename
* @version v X.Y
*
*/

class MY_Controller extends Controller {

function MY_Controller ()
{
parent::Controller();
$rutas = array('css_folder'=>$this->config->item('site_css'));
$this->load->vars($rutas);
}
}

Config.php

$config['site_css'] = $config['base_url'].'css/';

Site Header.
<?=$site_css;?> or <?=$css_folder;?> and show me this:


A PHP Error was encountered

Severity: Notice

Message: Undefined variable: site_css or css_folder (if print css_folder css_folder)

Filename: home/header.php

Line Number: 1




Theme © iAndrew 2016 - Forum software by © MyBB