How to redirect the user to another page with Codeiigniter?

Asked

Viewed 214 times

1

I’m starting with Codeigniter and I’m having a little difficulty linking the pages.

I’m doing it this way:

<li class="nav-item mr-3">
    <a class="nav-link page-scroll" href="<?php echo base_url('nomeApp/login');?>">Login</a>
</li>

My controller is like this

class Homepage extends CI_Controller{

function __construct(){
    parent::__construct();
    $this->load->helper('url');
}

public function index()
{
    $this->load->view('veloxmob/index');
}

public function login()
{
    $this->load->view('login/login');
}}

  • You need to have a controller nameApp, with the login function. In this login function, you return your view

  • Now just take the result of $this->load->view and print on the screen with echo

  • Can you show me an example ? Because it’s being a little confusing since I’m starting now in the code, this echo I insert inside my controller or link ?

  • echo $this->load->view('veloxmob/index'); will print the veloxmob index.php folder (inside the views folder)

1 answer

2


In this your tag is being redirected to the controller nameApp, but your controller is Homepage

try replacing the nameApp for Homepage on the tag

<li class="nav-item mr-3">
    <a class="nav-link page-scroll" href="<?php echo base_url('Homepage/login');?>">Login</a>
</li>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.