Welcome Guest, Not a member yet? Register   Sign In
region already defined Error Template Library Version 1.4.1
#1

[eluser]firebird[/eluser]
Hi there I am new to CI and I’ve just installed the Template Lib 1.4.1, and follow the document step by step, after I added two lines at the bottom of the file config/template.php:

$template[‘default’][‘regions’][‘header’] = array(‘content’ => array(’<h1>CI Rocks!</h1>’));
$template[‘default’][‘regions’][‘footer’] = array(‘content’ => array(’© Our Company Inc.’));

and when I run it from the browser I always get this Error:

An Error Was Encountered

The “header” region has already been defined.


I spend couple of days to check the code, but still can’t figure out what caused the problem, the above two lines just assign value to 'header' and 'footer' regions, not define them as they were already defined below:

$template['default']['regions'] = array(
'header',
'title',
'content',
'sidebar',
'footer',
);

can any expert here to give a comment? thanks.
#2

[eluser]WanWizard[/eluser]
Are you sure these two lines trigger the error?

This message is generated by add_region(), which is either called manually, or from set_regions(). set_regions() is called from the init method, using the config file as input. At that time, the regions are defined. As it uses an array, 'header' can not be present twice.

So the question is, what code is in your controller?
#3

[eluser]firebird[/eluser]
Thanks for your help, I am sure these two line of codes trigger the error, in config/template.php file
the configuration is as follows:
--------------------------------------
$template['active_group'] = 'default';
$template['default']['template'] = 'template.php';


$template['default']['regions'] = array(
'header',
'title',
'content',
'sidebar',
'footer',
);

$template['default']['parser'] = 'parser';
$template['default']['parser_method'] = 'parse';
$template['default']['parse_template'] = FALSE;

$template['default']['regions']['header'] = array('content' => array('<h1>CI Rocks!</h1>'));
$template['default']['regions']['footer'] = array('content' => array('<p id="copyright">@ Our Company Inc.</p>'));

-----------------------------------------------
I guess when the last two line assigning default content to header/footer regions, it complains that the header/footer regions has already
be defined earlier in this line of code(empty regions):


$template['default']['regions'] = array(
'header',
'title',
'content',
'sidebar',
'footer',
);


in my Page controller, I just call the render() method

$this->template->render();
#4

[eluser]WanWizard[/eluser]
At the end of your config file, do a
Code:
var_dump($template);
and all will become clear.

Code:
$template[‘default’][‘regions’] = array(
  ‘header’,                        
  ‘title’,
  ‘content’,
  ‘sidebar’,
  ‘footer’,
);
creates
Code:
array ( 0 => 'header',
1 => 'title',
2 => 'content',
3 => 'sidebar',
4 => 'footer'
);

When then use
Code:
$template[‘default’][‘regions’][‘header’] = array(‘content’ => array(’<h1>CI Rocks!</h1>’));
you create
Code:
array( 'header' = array('content' => 'whatever') );

So the error message is correct, you do have defined header and footer twice. Once as an array value, once as an array key with contents.

Remove 'header' and 'footer' from your first definition to prevent it. This is what the user guide says as well:
Quote:Regions can be extended to include default contents and wrapping markup if desired. To do this, turn your region keys into multidimensional arrays with...
#5

[eluser]Unknown[/eluser]
" Hello Everyone! If i shall powered to improve this forum, i will improve code library by uploading havvvy task on .NET and P H P then Active X System. "

=============================================================================================
BY Smith Jackson
<a href="http://www.findphoneservice.com/" rel="nofollow">Pink Mobile Phones</a>
#6

[eluser]firebird[/eluser]
Thanks a lots for your help, after I removed 'header','footer' regions from first definition, it solved the problem.
#7

[eluser]Unknown[/eluser]
Smile
i have also got this problem ...
after fix this code.. then fixed...
thank u Smile
#8

[eluser]Unknown[/eluser]
[quote author="smithjackson" date="1292519262"]" Hello Everyone! If i shall powered to improve this forum, i will improve code library by uploading havvvy task on .NET and P H P then Active X System. "

=============================================================================================
BY Smith Jackson
<a href="http://www.findphoneservice.com/" rel="nofollow">Pink Mobile Phones</a>[/quote]
#9

[eluser]Makelaly[/eluser]

Really impressed! Everything is very, very clear, open is a description of the problem. It contains the information.
#10

[eluser]Unknown[/eluser]
for a better understanding, see the below code.

Code:
$template['default']['template'] = 'template';
$template['default']['regions'] = array(
'header' => array('content' => array('<h1>CI Rocks!</h1>')),
'title',
'content',
'sidebar',
'footer'=>array('content' => array('<p id="copyright">© Own Company Inc.</p>')),
);
$template['default']['parser'] = 'parser';
$template['default']['parser_method'] = 'parse';
$template['default']['parse_template'] = FALSE;




Theme © iAndrew 2016 - Forum software by © MyBB