Reputation: 171
P.S This question may already be existing but the answer didn't satisfied what I was trying to figure out. I'm using code igniter for the first time in my new project.
So I have this only one controller which is main.php and populated with a lot of public function. Now everytime I go to main.php the url is looks like cmms/main
and everytime I'm going for its subclass it goes cmms/main/asset
.
Now the subclass asset has many functions which are in main.php. What I want is to make separate controllers for each module. so i have cmms/main
as main.php & cmms/asset
as asset.php instead of making it under cmms/main/asset
. Would this be possible? or I should just leave it alone and continue putting all codes in the main.php controller?
My default route is the main controller.
$route['default_controller'] = 'main';
Upvotes: 3
Views: 1221
Reputation: 38584
You have two ways to do that.
(these topics describe below)
go to - config/routes.php
, and add new routes like this
$route['cmms/asset'] = 'cmms/main/asset';
$route['cmms/contact'] = 'cmms/main/contact';
So in view you should call anchor tags like this
<a href= "<?php echo base_url() ?>cmms/asset">Assets</a>
<a href= "<?php echo base_url() ?>cmms/contact">Contact Us</a>
Create new controller for each new methods.
File name - main.php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class Main extends CI_Controller {
}
File name - asset.php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class Asset extends CI_Controller {
}
File name - contact.php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class Contact extends CI_Controller {
}
So in view you should call anchor tags like this
<a href= "<?php echo base_url() ?>asset">Assets</a>
<a href= "<?php echo base_url() ?>contact">Contact Us</a>
Upvotes: 1
Reputation: 604
it seems that you are having trouble to write long url each and every time....
So,better way is to use routes for ease. For Ex: $route['login'] = "main/login";
Now if you use login directly in url it will call main class and it's login method
using routes you can prevent exposing your controller name and also for shorten URl
Upvotes: 0
Reputation: 4574
you can create Modules for your class in following ways,
important please read documentation for HMVC extension to use it.
Upvotes: 1