Welcome Guest, Not a member yet? Register   Sign In
How to create admin panel
#1

[eluser]JasmineFlower[/eluser]
Hi,

I am using codeigniter 2.0.1 version.

Here is my directory structure..

/application/controllers/home.php (Default Home page)
/application/controllers/admin/login.php (Admin Directory)


http://localhost/projectfoldername - Home page is working fine..
http://localhost/projectfoldername/admin - Admin is not working.

Because in route default home page can come easily
but how to route admin page?

$route['admin']='admin/login/index'; but it considered admin as class and login as function

it display the 404 error. pls tell me how to route the admin folder
#2

[eluser]CrossMotion[/eluser]
Hi Jasmine_flower,

Make sure you don't have a admin.php file in the controllers folder, because it will overwrite the admin folder. And check if there are no conflicting rules in the route file.
#3

[eluser]InsiteFX[/eluser]
application/config/routes.php
Code:
//                    dir/controller/method
$route['login']    = "admin/admin/login";
$route['logout']   = "admin/admin/logout";
$route['register'] = "admin/admin/register";

controllers
  -- admin
  ---- admin.php - extended from Admin_Controller, login is the admin/method which will display the view file.
  ---- users.php - extended from Admin_Controller, for managing users

Code:
// these go into application/core
// NOTE: The class name doe's not have to be MY_Controller but the file has to be saved as MY_Controller.php

class MY_Controller extends CI_Controller {}

class Admin_Controller extends MY_Controller {}

class Public_Controller extends MY_Controller {}

// these go into application/controllers/admin - and would be used for a dashboard and managing users.
class Admin extends Admin_Controller {}
class Users extends Admin_Controller {}

// rest would be application/controlers for Public Controllers
class Main extends Public_Controller {}

Code:
// add this to the bottom of - application/config/config.php
/*
| -------------------------------------------------------------------
|  Native Autoload - by Phil Sturgeon. NOTE: A New Version!
| -------------------------------------------------------------------
|
| Nothing to do with config/autoload.php, this allows PHP autoload to work
| for base controllers and some third-party libraries.
|
| If using HMVC you do not need this! HMVC will SPL_Autoload.
|
| Place this code at the bottom of your application/config/config.php file.
*/
function __autoload($class)
{
    if (strpos($class, 'CI_') !== 0)
    {
        if (file_exists($file = APPPATH . 'core/' . $class . EXT))
        {
            include $file;
        }
        elseif (file_exists($file = APPPATH . 'libraries/' . $class . EXT))
        {
            include $file;
        }
    }
}

InsiteFX
#4

[eluser]JasmineFlower[/eluser]
Hi,

thanks for your reply..

I followed your instructions. I typed the url manually in the address bar like http://localhost/projectfolder name/admin, but the same error - Object not found - displayed. I don't know what mistake i did.

my folder structure is now
application/controllers/admin/admin.php - for Admin
application/controllers/home.php - for user

can you please explain me
#5

[eluser]CrossMotion[/eluser]
As far as I know, simple things as these don't require extending core classes and such. Just adding a route should be enough.

Can you post the code of your /controllers/admin/login.php controller and the routes you're currently using, to check if there might be something wrong there.
#6

[eluser]JasmineFlower[/eluser]
Hi,

My folder Structure

project folder name/application/controllers/admin folder/admin.php - for Admin
project folder name/application/controllers/home.php - for user

My route.php

Code:
$route['default_controller'] = "home";
$route['404_override'] = '';

$route['admin'] = "admin/admin/login";

my controller admin.php

Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Admin extends Admin_Controller
{

    
    public function index()
    {
        $this->load->helper('url');
        
    }
    public function login()
    {
        $this->load->view('admin/login');
    }
}


my user controller page home.php

Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Home extends CI_Controller
{

    
    public function index()
    {
        $this->load->helper('url');
        $this->load->view('home');
    }
    
}
#7

[eluser]CrossMotion[/eluser]
Just change
Code:
class Admin extends Admin_Controller
to
Code:
class Admin extends CI_Controller
in admin.php
#8

[eluser]JasmineFlower[/eluser]
I already tried it but still in that same error. What about the .htaccess file ?
#9

[eluser]CrossMotion[/eluser]
If you use the default htaccess file it should not be a problem. If you changed it, can you post it here?

Do you get a 404 error, or a php error? if its PHP, can you post it here to.

Also if you need the url helper in the login function, you need to put it in a __construct, like this:

Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Admin extends CI_Controller
{
    function __construct()
    {
      parent::__construct();    
      $this->load->helper('url');    
    }
  
    public function index()
    {
          
    }

    public function login()
    {
        $this->load->view('admin/login');
    }
}
#10

[eluser]InsiteFX[/eluser]
I would autoload the url helper because it is used so much!

InsiteFX




Theme © iAndrew 2016 - Forum software by © MyBB