I’am using a codeigniter 2.x. What i need is to insert a values into an array of config/template.php from inside of a view file /views/home.php.
I’ve created a custom config file application/config/template.php:
$config['site_name'] = "Sitename";
$config['site_lang'] = "En-en";
$config['page_name'] = "Pagename";
$config['css_page'] = "default";
$config['alias'] = "";
$config['head_meta'] = array(
'description' => 'description',
'keywords' => 'meta, keywords',
'stylesheets' => array(
'template.css'
),
'scripts' => array(
'jquery.js',
'template.js'
),
'charset' => 'UTF-8'
);
$config['sidebars'] = array();
Then, i use application/views/template/template.php as my main HTML layout, where at the beginning I include a file application/views/template/includes/inc-tpl-cfg.php which globalize my configurations for a template into an one file with arrays, so i could access them a little bit easier. Here is the content of that inc-tpl-cfg.php:
<?php
// No direct acces to this file
if (!defined('BASEPATH')) exit('No direct script access allowed');
/* Template configuration needs to be defined to make them accessible in the whole template */
$cfg_template = array(
'sitename' => $this->config->item('site_name'),
'sitelang' => $this->config->item('site_lang'),
'pagename' => $this->config->item('page_name'),
'csspage' => $this->config->item('css_page'),
'charset' => $this->config->item('charset','head_meta'),
'description' => $this->config->item('description','head_meta'),
'keywords' => $this->config->item('keywords','head_meta'),
'stylesheets' => $this->config->item('stylesheets','head_meta'),
'scripts' => $this->config->item('scripts','head_meta'),
'sidebars' => $this->config->item('sidebars')
);
/* Template variables */
$cfg_assetsUrl = base_url() . 'assets';
// If pagename exists than concatenate it with a sitename, else output only sitename
if(!empty($cfg_template['pagename'])){
$title = $cfg_template['pagename'] . ' - ' . $cfg_template['sitename'];
}else{
$title = $cfg_template['sitename'];
}
And one part in my main template layout is block with sidebars:
<div id="tpl-sidebar">
<?php foreach($cfg_template['sidebars'] as $sidebar):?>
<?php $this->load->view('modules/'. $sidebar);?>
<?php endforeach ;?>
</div>
And at last, it loads a application/views/home.php into the specific div block inside applications/views/template/template.php. This is a /views/home.php:
<?php
// No direct acces to this file
if (!defined('BASEPATH')) exit('No direct script access allowed');
// Page configuration
$this->config->set_item('page_name','Homepage');
$this->config->set_item('css_page','home');
$this->config->set_item('alias','home');
?>
<p>
WELCOME BLABLABLA
</p>
</h3>
There is a section where i can define/overwrite a default values from config/template.php and use a specific ones for each views. So my questions is, how can i extend a $config[sidebar] array inside this view file by inserting some new items, for exemple: recent.php,rss.php etc… ?
Sorry for a big code.
Thanks in advance.
Ok, i got it:
this is what i should insert inside of a
views/home.php:Thanks anyway.