CodeIgniter Forums
Required File Not Working properly ! - 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: Required File Not Working properly ! (/showthread.php?tid=53732)



Required File Not Working properly ! - El Forum - 08-06-2012

[eluser]osama[/eluser]
Hi, friends
i have two simple pages admin_check.php and dashboard.php
I'm using the admin check file to protect my admin pages so i put a very simple code in it to know if the user logged in or not then I'm using this file ( admin_check) in other files to do the log in check process but it's not working when i require it in other files

This is admin_check code :

Code:
<?php
class Admin_check extends CI_Controller {
    function index()
{
  if (!$this->tank_auth->is_logged_in()) {
   redirect('/auth/login/');
  } else {
   $user_id = $this->tank_auth->get_user_id();
   $username = $this->tank_auth->get_username();
            echo"Welcome ". $username ." Your ID is ". $user_id ." .";
  }
}
}
?>

and This is The dashboard Code :

Code:
<?php
require("admin_check.php");
class Dashboard extends CI_Controller {
    public function index()
    {
        echo"<h2> Here Are DashBoard !</h2>";
    }
?&gt;

Logically When i go to htttp://localhost/codeigniter/index.php/dashboard

it should redirect me to log in page But it doesn't so I'm Wondering what's Wrong ?:coolsmirk:


Required File Not Working properly ! - El Forum - 08-06-2012

[eluser]Clooner[/eluser]
You are overriding the index method! And this is not the preferred way to extend a controller. Please read http://ellislab.com/codeigniter/user-guide/general/creating_libraries.html especially the part about Extending Native Libraries. Go try that after reading the userguide and have another go at it.


Required File Not Working properly ! - El Forum - 08-06-2012

[eluser]solid9[/eluser]
try,
htttp://localhost/codeigniter/index.php/dashboard/admin_check/