Setting a module as homepage in codeigniter HMVC - php

Today I started using Codeigniter+the modular extension from wiredesignz(hmvc) and I have a lot of unanswered questions but for the moment I will stick only to 1 .I understood how the modules work and I want to create a test website where I have 3 modules ( home,about and blog ) .
My folder structure :
Home
|-controllers
|-models
|-views
About
|-controllers
|-models
|-views
Blog
|-controllers
|-models
|-views
Now the question : How can I make the home module to be seen as homepage/main page ? I tried with config
$config['base_url'] = 'modules/home'; it didn't work
I tried some tweaks from the main index file but unfortunately it bricked my code.
I tried with htaccess but nothing .
Thank you .

Each module may contain a config/routes.php file where routing and a default controller can be defined for that module using:
$route['module_name'] = 'controller_name';
Taken from wiredesignz.

Kiran above was bit close. I tried to do so on live environment but failed. Apparently, this would work only if your default module and default controller are same (that is, home). Otherwise, you'll have to specify the module name as well as the controller name. In my case, I specified module name and controller name in default controller and it picked up!
$route['default_controller'] = 'admin/home';
In your case, it would be:
$route['default_controller'] = 'home/controller_name';

It might help to you, if still you are waiting for answer, Change your default controller to "home" controller.
In config/routes.php
$route['default_controller'] = 'home';//home is the controller name of home module.

just go to your application\config\routes.php and change your default controller to the module and controller you want:
$route['default_controller'] = 'module/controller_name';

Related

HMVC Integration in Codeigniter view paths

I am trying to intregrate HMVC to codeigniter. I have installed the MX files to thrid_party and uploaded the MY_Loader , MY_Loader and MY_Model to the application/core folder. it is working fine
I have two issues
1) How to add the module routes that overide the application routes
I am accessing module through the link localhost/domain/admin/portfolio
I have tried adding routes.php to the modules config application/modules/portfolio/config/routes.php with below details
$route['admin/portfolio'] = 'portfolio/admin/portfolio';
$route['admin/portfolio/add'] = 'portfolio/admin/portfolio/edit';
$route['admin/portfolio/edit/(:num)'] = 'portfolio/admin/portfolio/edit/$1';
On my root application config already added a routes
$route['admin'] = 'admin/login';
Because of this route 'admin/login' in the application/config/routes.php it is showing page not found. To fix this I have currently added the module/portfolio/config/routes`` above the 'admin/login'. Is there any other method instead of adding it to theapplication/config/routes`.
2) How to access the module view files
I have controller accessing the view files from application/controlles/admin/
$this->load->view('admin/view_header',$data);
$this->load->view('admin/view_portfolio',$data);
$this->load->view('admin/view_footer');
You have placed your Portfolio Controller under
application/modules/portfolio/controllers/admin
which is fine.
Your route (which will hit the index by default) should be
$route['admin/portfolio'] = 'portfolio/admin/portfolio';
Aside: other naming considerations
What I tend to do is to create a controller with admin in the name...
So I would have PortfolioAdmin.php or something along those lines, so I know by the file name, it's admin "Stuff", when I am playing with it in my Editor/IDE.
UPDATE:
In regards to your
Nor this works Modules::run('admin/portfolio', $data);
So you would then use the full controller name... Do not use routes, they are for URLs. Any module you want to call from another module you always use the full name.
Modules::run('portfolio/admin/portfolio', $data);

Codeigniter 3.1.0: Only default route is working

I will preface my question by saying I have searched high and low for a solution to my problem, including, but not limited to, Stackoverflow, YouTube and Google.
My issue: Only my default route is working in Codeigniter. My default route is set to a controller called Home which loads a home.php view. That works fine. I have another controller called Pages which as of now has only one method, Contact which points to view of the same name.
My routes.php file looks like this.
$route['default_controller'] = 'home/home';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
// All custom routs go below this line.
$route['contact'] = 'pages/contact';
If I should change the default rout to 'pages/contact' my contact page shows.
My setup is as follows:
Windows 10
XAMMP 5.6.12
PHP 5.6.12
Any help would be greatly appreciated.
Default controller name should be like this $route['default_controller'] = 'home'; not like your $route['default_controller'] = 'home/home';
And then try it the url www.site.url/pages/contact is working or not if working then try
$route['contact'] = 'pages/contact';
Also you can debug your route with this link.

Codeigniter 3.0 routing problems

I'm new in Codeigniter framework and got routing problem.
I have Main controller and Tournaments controller.
My routes look like this:
$route['default_controller'] = 'main';
$route['main'] = 'main';
$route['tournaments/results/(:num)'] = 'tournaments/results/$1';
When I go to localhost/tournaments/results/1 and then click to link "Main" I got localhost/tournaments/results/main instead of localhost/main
What is wrong with my routes or maybe problem is somewhere else?
Probably your link to 'Main' is wrong, not your routes files. Check your link.

Codeigniter routing question

I have a CI application with organized folders.
I have several folders on views, controllers and models.
ie.:
/controllers/frontend/, controllers/backend
/views/frontend, views/backend
... etc ...
So if i want to access the function 'login' on the frontend controller i have to go to: http://localhost/frontend/login/index
What i want is to get rid of the need of typing 'frontend', so if i type http://localhost/login/index, it would be the same as http://localhost/frontend/login/index.
Of course i dont want to add them manually to the routes file, i want it to be recognized automatically.
Thanks.
Try changing line 17 in your config.php file in application\config.
$config['base_url'] = 'http://localhost/';
Change above to below:
$config['base_url'] = 'http://localhost/frontend/';
I know you don't want to change your routing for each controller, but if this is the only one you need to do a specific routing for, you can change the default controller in the Router file inside your application/config folder to:
$route['default_controller'] = 'frontend';
$route['(:any)'] = "frontend/some_secondary_variable";
The second line is only if you need to pass variables to the controller, otherwise, omit it.

Why are my URIs not working?

In my routes.php I have :
$route['default_controller'] = "bitcoin";
and in my config.php I have:
$config['base_url'] = 'http://localhost/bitcoin/';
$config['index_page'] = 'index.php';
here is my controller: http://www.pastie.org/2253458
When I try to go to the following, I get a 404 not found (but the 404 template looks different):
http://localhost/bitcoin/edit/
http://localhost/bitcoin/index.php/edit
You can't access functions through the default controller like this.. It's assumes your trying to access another controller. Default controller is used when nothing is passed, ie: index.php
You will need to go to /bitcoin/index.php/bitcoin/edit
And note you will only be able to go to /bitcoin/bitcoin/edit if you have a htaccess file setup for routing.
You didn't say if you've removed or not your index with .htaccess, but if you didn't, did you try using: http://localhost/index.php/bitcoin ?
Or better, since it's your default controller, just http://localhost ?
What you're doing is quite strange, I can't understand if you're in a subfolder called bitcoin (in case, it should be http://localhost/bitcoin/ to call the default controller, which is also called bitcoin but doesn't need to be indicated in your URL).
If you're in root, You should rewrite your urls as: http://localhost/index.php/bitcoin/edit to call the edit() method of your default controller
Edit:
If you're in a subfolder called bitcoin, your base url, with default controller, should be:
http://localhost/bitcoin/ (which is the same as http://localhost/bitcoin/index.php/bitcoin)
If you want to get the bitcoin method edit(), should be http://localhost/bitcoin/index.php/bitcoin/edit
Also, try removing your .htaccess AT ALL and see what happens.
Edit2
Oh, one last thing: use CI_Controller and not CI_controller, if you're on a OS where lowercase matters you might encounter some problems

Categories