How to move from one view to another in Codeigniter

You can move from one view to another in Codeigniter using the base_url() method in the anchor tag in the view file. You have to pass base_url('/link-to-visit') method to the anchor tag, create a route, controller method, and view file on which you want to visit.

Answers 1
  • Link to another page using base_url() in codeigniter 4

    <!-- Create about us page in views directory with html link  -->
    <!-- app\Views\<about-us>.php  -->
    <a href="<?php echo base_url('/contact-us'); ?>"> Contact us </a>
    <!-- Create a route for the contact-us page. -->
    <!-- app\Config\Routes.php -->
    $routes->get('/contact-us', 'Home::contact_us');
    <!--Home is controller name inside controllers and contact_us is the method name inside Home controller -->
    <!-- Create controller method in Home controller. -->
    <!-- app\Controllers\<Home>.php -->
    public function contact_us(){
        return view('contact-us');
    <!-- Create a contact-us page in the views directory -->
    <!-- app\Views\<contact-us>.php -->
    <p> Contact us page </p>
  • Back to code snippet queries related codeIgniter