How to move from one view to another in Codeigniter

Created at 23-May-2021 , By samar

How to move from one view to another in Codeigniter

Through many examples, we will learn how to resolve the "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.
  • 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

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Buy Me A Coffee

Don't forget to share this article! Help us spread the word by clicking the share button below.

We appreciate your support and are committed to providing you valuable and informative content.

We are thankful for your never ending support.