Skip to content

Instantly share code, notes, and snippets.

@mathewpeterson
Created June 7, 2012 15:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mathewpeterson/2889624 to your computer and use it in GitHub Desktop.
Save mathewpeterson/2889624 to your computer and use it in GitHub Desktop.
<?php
class MY_Controller extends CI_Controller
{
/**
* Takes the method passed to it for the router
* and loads a header and footer for all controller methods
* automatically setting an id and class for CSS Scoping
*
* @param string $method
* @return null
* @author Kenny Meyers
*/
public function _remap($method)
{
if(method_exists($this, $method))
{
//Get the current controller class and set it as the
//body class attribute
$body_class = strtolower(get_class($this));
// Index isn't a great id name, but since it's the index of
// the controller we set that
$body_id = ($method == "index") ? $body_class : $method;
$this->load->view('_shared/header.html', array('body_id' => $body_id, 'body_class' => $body_class));
$this->$method();
$this->load->view('_shared/footer.html');
}
else
{
show_404();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment