CodeIgniter Forums
Base_url() code not working - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Base_url() code not working (/showthread.php?tid=488)



Base_url() code not working - Jiji - 12-09-2014

I'm creating a CRUD basic application using CodeIgniter. I have created a link for "Insert New User", and within the href of the anchor tag I specified the base url along with the controller name and function name. The code is as below.
PHP Code:
<a href="<?php echo base_url();?>index.php/user/add_form">Insert New User</a

config.php code

Code:
$config['base_url']    = 'http://localhost/crudcodeig/';

my controller- users.php

PHP Code:
class Users extends CI_Controller
    
{
         public function 
add_form()
        {
            
$this->load->view('insert');
        }
         } 

The problem is I can't view the link specified within the a href. Help is appreciated. Thanks!


RE: Base_url() code not working - Dracula - 12-10-2014

(12-09-2014, 09:35 PM)Jiji Wrote: I'm creating a CRUD basic application using CodeIgniter. I have created a link for "Insert New User", and within the href of the anchor tag I specified the base url along with the controller name and function name. The code is as below.


PHP Code:
<a href="<?php echo base_url();?>index.php/user/add_form">Insert New User</a

config.php code



Code:
$config['base_url']    = 'http://localhost/crudcodeig/';

my controller- users.php



PHP Code:
class Users extends CI_Controller
    
{
 
        public function add_form()
        {
            
$this->load->view('insert');
        }
 
        

The problem is I can't view the link specified within the a href. Help is appreciated. Thanks!


Try this:

PHP Code:
<a href="<?php echo site_url('index.php/user/add_form'); ?>">Insert New User</a



RE: Base_url() code not working - bw.balazs - 12-10-2014

It could be a problem if you didn't load the URL helper in the controller (or autoload it if you regularly use it).
PHP Code:
$this->load->helper('url'); 
I think it will solve the problem.