CraZyDroiD
CraZyDroiD

Reputation: 7105

Codeigniter page routing

I'm new to Codeigniter and i have a problem in page routing. I have a button placed in my first page

<center><a href="" class="button1">Start</a></center>

I have a page in my view folder. I want to direct to this page when i click my button. How can i navigate to my page in view folder on button click.

My base url

$config['base_url'] = 'http://localhost/xampp/CodeIgniter/';

Thanks in advance

Upvotes: 0

Views: 169

Answers (4)

deviloper
deviloper

Reputation: 7240

As you are using codeigniter, you could simply name the function in the contorller that would load the page you want.

<center><a href="<?=base_url().'ControllerName/functionName';?>" class="button1">Start</a></center>

or depending on your configurations:

<center><a href="<?=base_url().'index.php/ControllerName/functionName';?>" class="button1">Start</a></center>

in the controllerName and the functionName:

// Other code ...
$this->load->view('viewFileName');

Upvotes: 1

Ricky
Ricky

Reputation: 568

Your base url is incorrect

replcae

$config['base_url'] = 'http://localhost/xampp/CodeIgniter/';

to'

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

then

<center><a href="<?php site_url('ControllerName/functionName');?>" class="button1">Start</a></center>

Read this tutorial for more http://w3code.in/2015/10/codeigniter-installation-beginner-guide/

Upvotes: 0

Siddhartha esunuri
Siddhartha esunuri

Reputation: 1144

First you need enable url library

$this->load->helper('url');

then test base_url(); function

Returns your site base URL, as specified in your config file. Example:

echo base_url();

And Calling view page, Suppose your file name is home.php

<?php
class Example extends CI_Controller {

    function index()
    {
        $this->load->view('home');
    }
}
?>

Upvotes: 0

Nere
Nere

Reputation: 4097

First load url_helper by

$this->load->helper('url');

Or in your autoload.php set

$autoload['helper'] = ['url'];

Then

<a href="<?php echo site_url() ?>" class="button1">Start</a>

Note: Use site_url() instead of base_url(), base_url() suited for src like

<img src="<?php echo base_url()" /> ....

Upvotes: 0

Related Questions