Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Creating the View for CodeIgniter
#1

    Creating the View for CodeIgniter
   

Creating the View for CodeIgniter


   

We'll create a view that will display the list of agencies.


   
           
  1. Enter the app/Views folder, and create a new file titled agencies.php. The file’s name has to correspond to the view that you told the controller to load, featured in the last line of the view() method.
  2.        
  3. Paste in the following code and save the file:
  4.    
   
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  </head>
  <body>
    <div class="row mt-3">
      <table class="table table-bordered" id="agencies">
        <thead>
          <tr>
            <th>Id</th>
            <th>Name</th>
            <th>Email</th>
          </tr>
        </thead>
        <tbody>
          <?php if($agencies): ?>
            <?php foreach($agencies as $agencies1): ?>
              <tr>
                <td><?php echo $agencies1['id']; ?></td>
                <td><?php echo $agencies1['name']; ?></td>
                <td><?php echo $agencies1['email']; ?></td>
              </tr>
            <?php endforeach; ?>
          <?php endif; ?>
        </tbody>
      </table>
    </div>
  </body>
</html>
   
   

The view will display the information passed by the controller in the $data array. The results won’t be stunning since we haven’t added styling to our view. However, you can add inline styling or reference a CSS stylesheet in the view later.

Our sample application is complete. You should be able to run this application by entering the following URL in your browser:
http://yourdomain.com/Agencies

The web application will call the agencies’ controller created and sort the elements of the database.

   


Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)