EllisLab text mark
Advanced Search
     
I’m confused, where should simple code that appears on all pages?
Posted: 21 July 2007 07:16 PM   [ Ignore ]
Joined: 2007-07-18
92 posts

For example on each page I have the following code. Before code igniter I would just stick this in the header include file, but now I’m not sure where the “best” place to put this is. It should appear on every single page, but it seems wrong to stick it directly in the header_view. Should I create a helper or library?. Any help is appreciated, thanks.

header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0'FALSE);
header('Pragma: no-cache'); 
 Signature 

Check it out: Critique Computer Products

 
Posted: 21 July 2007 07:37 PM   [ Ignore ]   [ # 1 ]   [ Rating: 0 ]
Avatar
Joined: 2007-02-06
743 posts

agraddy did something similar. He created a library for headers:
http://ellislab.com/forums/viewthread/51313/#250141

Instead, you could just make a plugin/helper since you don’t really need an object for this.

Additionally, you could create a parent controller that loads/calls the header plugin/helper/library in its constructor. That way you wouldn’t have to load the plugin/helper/library in every controller, just extend the parent controller.

 Signature 

“I am the terror that flaps in the night”

 
Posted: 21 July 2007 08:02 PM   [ Ignore ]   [ # 2 ]   [ Rating: 0 ]
Joined: 2007-07-18
92 posts

That’s perfect, thanks! I think I will make an initialization_header helper that contains all those functions, and load it in a parent controller. I need to look into the parent controller thing but it sounds good to me.

 Signature 

Check it out: Critique Computer Products

 
Posted: 21 July 2007 08:47 PM   [ Ignore ]   [ # 3 ]   [ Rating: 0 ]
Joined: 2007-07-18
92 posts

I went the parent controller route, but something weird is going on. Nothing in the parent controller does anything, it seems like it is being ignored. I have it setup like this. For simplicity sake I just wrote an echo statement in each one which should be fired off when the welcome controller is called. At this moment just the welcome echo goes off.

Directory:
- template_engine.php (parent)
- welcome.php (child)

template_engine.php

<?php
class TemplateEngine extends Controller {
 
 
function __construct()
 
{
  parent
::Controller();
  
  echo 
"TemplateEngine Created";
 
}
}
?> 


welcome.php

<?php

require_once 'template_engine.php';

class 
Welcome extends TemplateEngine {
 
 
function __construct()
 
{
  parent
::Controller(); 
   echo 
"Welcome Created";
  
}
 Signature 

Check it out: Critique Computer Products

 
Posted: 21 July 2007 08:57 PM   [ Ignore ]   [ # 4 ]   [ Rating: 0 ]
Joined: 2007-07-18
92 posts

Nvm I found the problem. I was calling parent::Controller(); in both when I should have called parent::__construct(); because I was using the wrong names… I see now why the have that generic __construct function in PHP 5 it really does save you from errors.

 Signature 

Check it out: Critique Computer Products