php - Integrating CodeIgniter libraries (like tank auth) -


i've done quite bit of research , haven't found satisfying answer.

how should use codeigniter libraries such tank auth? i've found handful of ways, seem sort of lackluster:

  1. do use controller is, adding controller functions/including styles needed?
  2. do use controller example model own after, relying on calls $this->tank_auth , views included tank auth?
  3. or extend my_controller tank-auth controller, extend particular controller needs authentication, , call parent::login() (or register(), activate(), etc )?

the first option seems best, seems difficult avoid copying lot of code (what happens if want login form, don't want redirect /auth/login?)

the second option has same problem, worse. need include logic of tank auth controller's login function each time wanted use login_form view, correct?

the last seems hacky , seems anti-mvc me, maybe i'm wrong.

check out http://philsturgeon.co.uk/blog/2010/02/codeigniter-base-classes-keeping-it-dry

pseudocode (see link - example there):

application/config/config.php

$autoload = array('tank_auth');  // add bottom of config.php per directions in link function __autoload($class) {      if(strpos($class, 'ci_') !== 0)      {         @include_once( apppath . 'core/'. $class . ext );      } } 

application/core/private_controller.php

class private_controller extends ci_controller {     function __construct()     {         parent::__construct();          if(! $this->tank_auth->is_logged_in()){             redirect('auth/login');         }     } } 

controller

 class privatestuff extends private_controller {      function index() {          echo "you logged in";      }  } 

-

http://example.com/index.php/privatestuff/ >you logged in 

as far views, can use ones came lib are, customize them, or create own -- you.


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -