EllisLab text mark
Advanced Search
     
region already defined Error Template Library Version 1.4.1
Posted: 15 December 2010 08:20 PM
Joined: 2010-12-15
4 posts

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.

 
Posted: 16 December 2010 04:04 AM   [ # 1 ]   [ Rating: 0 ]
Avatar
Joined: 2008-11-04
4489 posts

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?

 Signature 

Me: WanWizard.eu | My company: Exite | Datamapper: DataMapper ORM <= LOOKING FOR A NEW MAINTAINER!

 
Posted: 16 December 2010 06:33 AM   [ # 2 ]   [ Rating: 0 ]
Joined: 2010-12-15
4 posts

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(’@ Our Company Inc.’));

———————————————————————-
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();

 
Posted: 16 December 2010 10:08 AM   [ # 3 ]   [ Rating: 0 ]
Avatar
Joined: 2008-11-04
4489 posts

At the end of your config file, do a

var_dump($template); 

and all will become clear.

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

creates

array ( => 'header',
 
=> 'title',
 
=> 'content',
 
=> 'sidebar',
 
=> 'footer'
); 

When then use

$template[‘default’][‘regions’][‘header’] = array(‘content’ => array(<h1>CI Rocks!</h1>)); 

you create

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:

Regions can be extended to include default contents and wrapping markup if desired. To do this, turn your region keys into multidimensional arrays with…

 Signature 

Me: WanWizard.eu | My company: Exite | Datamapper: DataMapper ORM <= LOOKING FOR A NEW MAINTAINER!

 
Posted: 16 December 2010 12:07 PM   [ # 4 ]   [ Rating: 0 ]
Joined: 2010-10-03
1 posts

” 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
Pink Mobile Phones

 
Posted: 18 December 2010 05:42 AM   [ # 5 ]   [ Rating: 0 ]
Joined: 2010-12-15
4 posts

Thanks a lots for your help, after I removed ‘header’,‘footer’ regions from first definition, it solved the problem.

 
Posted: 24 October 2012 04:26 PM   [ # 6 ]   [ Rating: 0 ]
Joined: 2012-10-24
1 posts

smile
i have also got this problem ...
after fix this code.. then fixed…
thank u smile

 
Posted: 25 October 2012 01:48 AM   [ # 7 ]   [ Rating: 0 ]
Joined: 2012-10-25
1 posts
smithjackson - 16 December 2010 12:07 PM

” 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
Pink Mobile Phones

 
Posted: 25 October 2012 09:23 PM   [ # 8 ]   [ Rating: 0 ]
Joined: 2012-10-24
2 posts

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

 
Posted: 05 April 2013 03:22 AM   [ # 9 ]   [ Rating: 0 ]
Joined: 2013-04-05
1 posts

for a better understanding, see the below 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