CodeIgniter Forums
Frontend and Backend (Base controllers) - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Frontend and Backend (Base controllers) (/showthread.php?tid=56794)

Pages: 1 2


Frontend and Backend (Base controllers) - El Forum - 01-22-2013

[eluser]Aken[/eluser]
I'm not going to watch a whole video tutorial series to figure out your point.


Frontend and Backend (Base controllers) - El Forum - 01-22-2013

[eluser]cPage[/eluser]
Quote:I don't know if you're confusing terminology, but you never want libraries to extend a controller class.

What do you think you do when you do this :


Code:
class Common
{
private $ci;

public function __construct()
{
   $this->ci =& get_instance();
} ....

/* Location: ./application/libraries/common.php */


Anyway this code looks great for me :

Code:
<?php
class Admin extends Admin_Controller
{
function __construct()
{
  parent::__construct();
}

public function index()
{
  $this->data['header']['title'] = 'Administration';
  $this->data['nav']['active'] = 'administration';
  $this->data['content'] => $this->admin_model->dashboard($this->data['group']);
  
  $this->template->set('header', $this->config->item('theme_url').'header', $this->data['header']);
  $this->template->set('nav', $this->config->item('theme_url').'admin/nav', $this->data['nav']);
  $this->template->set('content', $this->config->item('theme_url').'admin/'.$this->data['group'], $this->data['content']);
  $this->template->load($this->config->item('theme_url').'m_template');
}
}
?>



Frontend and Backend (Base controllers) - El Forum - 01-22-2013

[eluser]Aken[/eluser]
I said you never want a library to extend a controller class. So considering I don't see anything like this:

Code:
class Common extends CI_Controller

That's not what's happening. I quoted your own words from your own post.


Frontend and Backend (Base controllers) - El Forum - 01-23-2013

[eluser]xerobytez[/eluser]
I think there was a mix up in terminology as well, when reading at first I got the same impression that Aken got which was you were trying to extend controllers from libraries which is no good obviously. Anyway, that autoload snippet doesn't help by loading base controllers from /libraries. I use a similar function when I want to have admin_controller or frontend_controller or whatever, this one is by Phil Sturgeon and is also placed in config.php. However it loads controllers from the /application/core directory which I think is better personally.

http://philsturgeon.co.uk/blog/2010/02/CodeIgniter-base-Classes-Keeping-it-DRY

Code:
function __autoload($class)
{
if(strpos($class, 'CI_') !== 0)
{
  @include_once( APPPATH . 'core/'. $class . EXT );
}
}

Good luck with your project.


Frontend and Backend (Base controllers) - El Forum - 01-23-2013

[eluser]cPage[/eluser]
Thank you very much for the link