Jenz
Jenz

Reputation: 8369

Setting up admin panel in Codeigniter

In my project I am trying to create one section for admin. Following http://philsturgeon.co.uk/blog/2009/07/Create-an-Admin-panel-with-CodeIgniter#top I tried the second method. According to it, my folder structure is changed to somewhat like this.

project
   cache
   config
   controllers
       -admin
          index.php
       -blog.php
   system
   views
       -admin
          index.php
        blog.php
...................

I have created one controller index.php inside controllers/admin with following code:

class Index extends CI_Controller
{
    function __construct()
    {
        parent::__construct();
    }

    function index()
    {
        $this->load->view(index/index);
    }
}

And inside views/admin I have created a file index.php and echoed some string and in routes.php I have added this line,

$route['admin'] = 'admin/index';

But when I run the admin panel using the url, http://localhost/workspace/project/admin/, I am getting the 404 error

The requested URL /workspace/project/admin/ was not found on this server.

What I am doing wrong? Is there any other settings I have to make.

Can someone please guide me to fix this ? I am new to Codeigniter.

Thanks in advance.

Upvotes: 1

Views: 14850

Answers (4)

Rakesh Sharma
Rakesh Sharma

Reputation: 13728

let change your files structure (You need to create an index function in your admin.php controller)

 project(may be root folder of CI)
    applications
       cache
       config
       controllers
           -admin
             index.php (method index)
           -blog.php
       system
       views
           -admin
              index.php
            blog.php

also change controller name to admin and view load

class Index extends CI_Controller
{
    function __construct()
    {
        parent::__construct();
    }

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

then change your route

$route['admin'] = 'admin/index';

Upvotes: 1

Dexter
Dexter

Reputation: 1796

try this

class Index extends CI_Controller
{
    function __construct()
    {
        parent::__construct();
    }

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

Upvotes: 0

sunny
sunny

Reputation: 1166

EDIT- change routes to admin to this in routes.php

$route['admin/(:any)'] = "admin/$1";

Also, place this above your routes to default controller-

 $route['default_controller'] = "welcome";
    $route['404_override'] = ''; 

I hope it works! ////////////////////////////////////////////

I guess, something is wrong with your structure, If i am not wrong then its something like this-

project
   cache
   config
   controllers
       -admin   // your admin folder
          index.php   // your default controller
       -blog.php
   system
   views
       -admin
          index.php
        blog.php

change the controller name from index to admin.php Hence the routes should be-

$route['admin'] = 'admin/admin/index'; // its like folder/controller/function

Upvotes: 1

vinay rajan
vinay rajan

Reputation: 361

I prefer that you have 2 codeigniter projects one for admin and one for blog. As there would be common folders like images, css and js which would conflict.

There will also be salablility issues like common controller names as namespace in codeigniter is still a lengthy process to follow.

Upvotes: 0

Related Questions