Welcome Guest, Not a member yet? Register   Sign In
Sub Folder Problem
#1
Big Grin 

Hi,

I started to develop CMS system and it will have 2 subfolder like, admin and interface. Interface will store frontend controllers and  I will use admin as management controller. The problem is when i change default route like

$route['default_controller'] = "interface/className/methodName";

But I got 404 error. Class and method name are correct even I check capital letters.

[Image: EEB00_A489_E68_FB0_B4_A63_C51_C56_B83_DF...C49_B1.png]
resim gönder
Reply
#2

(02-05-2015, 04:20 AM)kazimkaragul Wrote: Hi,

I started to develop CMS system and it will have 2 subfolder like, admin and interface. Interface will store frontend controllers and  I will use admin as management controller. The problem is when i change default route like

$route['default_controller'] = "interface/className/methodName";

But I got 404 error. Class and method name are correct even I check capital letters.

[Image: EEB00_A489_E68_FB0_B4_A63_C51_C56_B83_DF...C49_B1.png]
resim gönder

What I do and you can do is create a main controller (put in the application/core folder) that extends the CI_Controller like so:
PHP Code:
class MY_Controller extends CI_Controller {
public function 
__construct() {
parent::__construct();
}


Then you can create two controllers that will be put into the application/libraries folder that will extend you main application controller (MY_Controller.php). I call mine Admin_Controller.php and Frontend_Controller.php:
PHP Code:
/* application/libraries/Admin_Controller.php */
class Admin_Controller extends MY_Controller {
public function 
__construct() {
parent::_contruct();
}
}

/* application/libraries/Frontend_Controller.php */
class Frontend_Controller extends MY_Controller {
public function 
__construct() {
parent::_contruct();
}


And finally for your controllers that are for the "admin area", they will extend the Admin_Controller. Your urls will look like :

http://example.com/admin/blog/edit/1

Also to make this all work you will need to put the following autoload function from (I believe) Phil Sturgeon at the top of your application/config/config.php file to tell Codeigniter to autoload the Admin or Frontend Controller depending on what is being "extended"

PHP Code:
function __autoload($classname) {

 if (
strpos($classname'CI_') !== 0) {

 
$file APPPATH 'libraries/'$classname '.php';

 if (
file_exists($file) AND is_file($file)) {

 @include_once(
$file);

 }

 }



Also update your application/config/routes.php file accordingly. So if your main admin page/controller is the dashboard controller & index function insert
PHP Code:
// set your default controller to the main controller that will extend your frontend controller and add: 
$route['admin'] = 'admin/dashboard'

I hope this helped and I didn't confuse you or talk in circles too much.
Reply
#3

Phil was putting the Base Controllers in the /core dir, which makes more sense. They're controllers, NOT libraries.

See how Phil was doing it: https://philsturgeon.uk/blog/2010/02/Cod...ng-it-DRY/

It loads from the /core dir. If you still want it to be able to autoload libraries, you could first see if the file exists in /core, and if not check /libraries.
Reply
#4

default_controller doesn't accept directories, only controller and method names.
Reply
#5

(02-05-2015, 09:23 AM)egall8 Wrote:
(02-05-2015, 04:20 AM)kazimkaragul Wrote: Hi,

I started to develop CMS system and it will have 2 subfolder like, admin and interface. Interface will store frontend controllers and  I will use admin as management controller. The problem is when i change default route like

$route['default_controller'] = "interface/className/methodName";

But I got 404 error. Class and method name are correct even I check capital letters.

[Image: EEB00_A489_E68_FB0_B4_A63_C51_C56_B83_DF...C49_B1.png]
resim gönder

What I do and you can do is create a main controller (put in the application/core folder) that extends the CI_Controller like so:

PHP Code:
class MY_Controller extends CI_Controller {
public function 
__construct() {
parent::__construct();
}


Then you can create two controllers that will be put into the application/libraries folder that will extend you main application controller (MY_Controller.php). I call mine Admin_Controller.php and Frontend_Controller.php:

PHP Code:
/* application/libraries/Admin_Controller.php */
class Admin_Controller extends MY_Controller {
public function 
__construct() {
parent::_contruct();
}
}

/* application/libraries/Frontend_Controller.php */
class Frontend_Controller extends MY_Controller {
public function 
__construct() {
parent::_contruct();
}


And finally for your controllers that are for the "admin area", they will extend the Admin_Controller. Your urls will look like :

http://example.com/admin/blog/edit/1

Also to make this all work you will need to put the following autoload function from (I believe) Phil Sturgeon at the top of your application/config/config.php file to tell Codeigniter to autoload the Admin or Frontend Controller depending on what is being "extended"


PHP Code:
function __autoload($classname) {

 if (
strpos($classname'CI_') !== 0) {

 
$file APPPATH 'libraries/'$classname '.php';

 if (
file_exists($file) AND is_file($file)) {

 @include_once(
$file);

 }

 }



Also update your application/config/routes.php file accordingly. So if your main admin page/controller is the dashboard controller & index function insert

PHP Code:
// set your default controller to the main controller that will extend your frontend controller and add: 
$route['admin'] = 'admin/dashboard'

I hope this helped and I didn't confuse you or talk in circles too much.


Thank you for answer but I just want to create subfolder. I am trying to create a kind of HMVC structure.
Reply
#6

I could not solve problem yet. Do you have any idea about solution?
Reply




Theme © iAndrew 2016 - Forum software by © MyBB