Welcome Guest, Not a member yet? Register   Sign In
I'm confused, where should simple code that appears on all pages?
#1

[eluser]chobo[/eluser]
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.


Code:
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');
#2

[eluser]Rick Jolly[/eluser]
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.
#3

[eluser]chobo[/eluser]
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.
#4

[eluser]chobo[/eluser]
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
Code:
<?php
class TemplateEngine extends Controller {

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


welcome.php
Code:
<?php

require_once 'template_engine.php';

class Welcome extends TemplateEngine {

function __construct()
{
  parent::Controller();
   echo "Welcome Created";
  }
}
#5

[eluser]chobo[/eluser]
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.




Theme © iAndrew 2016 - Forum software by © MyBB