0

I am using hmvc for creating a register page :- In the url now I am typing :- http://localhost/CI/index.php/user/registration

user is the module name

controller :- registration.php

<?php
class Registration extends MX_Controller{
    function index() {
        $this->load->view('homepage');
    }

    function register(){
        $this->load->view('registrationPage');
    }
}
?>

view :- homepage.php

<html>
<body>
    <a href="registration/register">register</a>
</body>
</html>

the problem is that in my url i have to type http://localhost/CI/index.php/user/registration/register for coming to registration page.

I want http://localhost/CI/index.php/user/register how can we do this.? setting base_url is not working and setting routes ia also not working. Is this possible to go to any page without giving module name in the url..?

tereško
  • 58,060
  • 25
  • 98
  • 150
avinashse
  • 1,440
  • 4
  • 30
  • 55

4 Answers4

2

Edit you routes.php file under config folder

$route['user/register'] = 'user/registration/register';
Miqdad Ali
  • 6,129
  • 7
  • 31
  • 50
0

You could use url rewrite in .htaccess file See url rewriting without htaccess and how to do url-rewriting in PHP

In CodeIgniter, .htaccess is present in system/application/config/config.php

Get more info here as I am not aware of CodeIgniter

Community
  • 1
  • 1
Vimalnath
  • 6,373
  • 2
  • 26
  • 47
0

You should create a proper URL for your site by adding an entry in your host file. For example:

127.0.0.1 http://mysitename

or

127.0.0.1 http://localhost.mysitename

Google up how to set a virtual host in apache. You should be able to find plenty of articles about that. Now edit your apache config to enable virtual hosts. With this feature enabled you will create a virtual host entry for your site. The virtual host tells apache to map the URL you've chosen to the specific directory path of your project files. (This way the actual directory path is not part of your URL.)

Next you should edit your .htaccess so that requests are always routed through the index.php front controller. Once this is done you will not have to use '/index.php/' as part of each URL. Read the section in the Code Igniter user guide called Code Igniter URLs. It has sample .htaccess configurations. Moreover, it explains how Code Igniter URLs work.

In order for CI to work with the virtual host, you must set the base URL in your CI config file to match the v-host URL.

Once you've completed all of this, you will need to restart apache.

Now you can just name your controllers and methods in accordance with the URL structure you want. In this case, a controller called user.php with a method called register.

DaveShaw
  • 52,123
  • 16
  • 112
  • 141
Neil Girardi
  • 4,533
  • 1
  • 28
  • 45
  • Hmm thanks for the reply... but i am using hmvc in codeigniter, and user is my module name controller name is registration and funciton is register.. what I am getting in the url is:- `../index.php/module_name/controller_name/controller_function`. and I want only `../index.php/controller_name/controller_function` not to include module name.. is there is a way to do that..? – avinashse Jul 06 '12 at 07:58
  • can you please tell me what for bonfire is used ? – avinashse Jul 06 '12 at 13:30
0

Is it a must to use HMVC in your project? Otherwise go for simple Codeigniter way because that is what you expect in this situation.

Nish
  • 2,296
  • 2
  • 14
  • 19
  • hmmm... hmvc will seperate every modules.. it can be done with an with simple codeigniter but in that i cant create different modules..so I am using HMVC] – avinashse Jul 06 '12 at 12:52