Welcome Guest, Not a member yet? Register   Sign In
Ion_Auth
#1

[eluser]davehedgehog[/eluser]
Hey wonder if any of you guys could help me out?

So Ive installed CI and written a blog and then intalled Ion_Auth, from here Ive been following a few tutorials to set up the login system etc.

first up I followed this

http://jondavidjohn.com/blog/2011/01/sca...r-ion_auth

I set the autoload libraries and the prefix MY_Controller.php

then created the MY_Controller.php in the core folder with the code as follows~

Code:
class Admin_Controller extends MY_Controller {

//create a class wide var to store object
protected $the_user;

public function __construct(){

  parent::__construct();

  //check if admin group
  if ( $this->ion_auth->is_admin()){
  
   //store the user as class wide var
   $this->the_user = $this->ion_auth->user()->row();

   //also store as var
   $data->the_user = $this->the_user;

   //load in views
   $this->load->vars($data);
  }
  else{
   redirect('/');
  }
}
}

class User_Controller extends MY_Controller {

//create a class wide var to store object
protected $the_user;

public function __construct(){

  parent::__construct();

  //check if admin group
  if ( $this->ion_auth->in_group('user')){
  
   //store the user as class wide var
   $this->the_user = $this->ion_auth->user()->row();

   //also store as var
   $data->the_user = $this->the_user;

   //load in views
   $this->load->vars($data);
  }
  else{
   redirect('/');
  }
}
}

class Common_Auth_Controller extends MY_Controller {

//create a class wide var to store object
protected $the_user;

public function __construct(){

  parent::__construct();

  //check if admin group
  if ( $this->ion_auth->logged_in()){
  
   //store the user as class wide var
   $this->the_user = $this->ion_auth->user()->row();

   //also store as var
   $data->the_user = $this->the_user;

   //load in views
   $this->load->vars($data);
  }
  else{
   redirect('/');
  }
}
}


Next I set up the controller folder structure with public, common_auth, user and admin. Then I added the controllers for anyone to view in public and others such as to create blog item in admin. The admin/blog.php being class Blog extends MY_Controller or even Admin_controller, both dont work and give me and error for either.

so my guess is Im still not calling the MY_Controller, so I followed this tutorial~

http://www.kylenoland.com/a-comprehensiv...-ion-auth/

to include the MY_Controller and still errors :/

can anyone point out what im missing?
#2

[eluser]jmadsen[/eluser]
It would be helpful if you told us what the errors were
#3

[eluser]TheFuzzy0ne[/eluser]
First of all, you should only ever define one class per file.

As for my controller, it should look something like this:

./application/core/MY_Controller.php
Code:
class MY_Controller extends CI_Controller {
    
    /* Your methods here */
}

Then CodeIgniter will automatically load it so you can extend it.

Does this help at all?
#4

[eluser]davehedgehog[/eluser]
Right, uh kind of :/ um whats confusing me is do I then create Admin_Controller.php...etc. and store them in the app/core/ or app/controllers/ ?




Theme © iAndrew 2016 - Forum software by © MyBB