CodeIgniter Responses

Creating a view

Create a new file in views folder, write HTML there.

Displaying a view

use view() function in controller to load view file

echo view('view_name');

Storing views in subdirectory 

echo view('directory_name/view_name')

Adding dynamic data to view

echo view('users', $data);

Access dynamic data at view

<?= $id ?>
<?= $name ?>

Alternate PHP Syntax at CodeIgniter

Alternative of echo

<?= $name ?>

Alternative of if else

if( $amount > 2000):
         $discount= $amount*5/100;

Alternative of foreach

foreach($items as $item):
    <li><?= $item ?></li>

View layout

    <title>My Layout</title>
    <?= $this->renderSection('content') ?>

Using layout in view

<?= $this->extends('layout_name') ?>
<?= $this->section('content') ?>
....................... write data here
<?= $this->endSection() ?>

Include partial view

<?= $this->include('navbar') ?>
© 2016 - 2022, All Rights are Reserved.