Search code examples
codeigniterbase-url

Codeigniter base_url() in whack?


I was trying to set up a basic log in form with a following code:

<?=form_open(base_url() . 'main/login'); ?>

However after submitting the form the url shows this:

example.com/main/http//example.com/http//example.com/main/login

So I guess in essence for some reason the base-url is printed twice before the controller/method declaration. If I clear the base url value in my config file then the application works normally. I am however curious on what could cause this. For additional information I am working on xampp with a virtualhost and I have mod-rewrite on with a .htaccess file located at the document root.


Solution

  • CodeIgniter automatically adds the base_url to the action of the form when you use the form helper.

    For example, you can use:

    <?=form_open('main/login'); ?>
    

    which will produce: http//example.com/main/login

    And a correct URL! Pretty simple! :D More information at: http://codeigniter.com/user_guide/helpers/form_helper.html