Room is library to help you make a layout for views easily, Room is similiar with Layout Views in Codeigniter 4
How to install this Library
- Download this project
- Move Room.php to your-codeigniter-project-folder/application/library
- Open your-codeigniter-project-folder/application/config/autoload.php
- Add 'room' to $autoload['libraries']
- Then you can use the Room !
<html lang="en">
<head>
<meta charset="utf-8">
<title>Welcome to CodeIgniter</title>
</head>
<body>
<?=$room->declare('content')?>
</body>
</html>
The declare method only have one argument - the name of room, That way any child views know what to name the opened room .
<?=$room->extend('welcome')?>
You must put the extend after all room has opened
<?=$room->open('content')?>
Hello World
<?=$room->close()?>
The open method only have one argument - the name of room, and close method dont need any argument. That way any room with similiar name to parent view will be replaced
<?=$room->open('content')?>
Hello World
<?=$room->close()?>
<?=$room->extend('welcome')?>
if you don't change the name of library :
public function index(){
$this->room->load('content');
}
if you want to pass a data to View :
public function index(){
$data = [
'hello'=> "World"
];
$this->room->load('content', $data);
}
In CI3 native, you'll access data with $hello, but we must using a different way
<?=$room->open('content')?>
Hello <?=$room->data('hello')?>
<?=$room->close()?>
<?=$room->extend('welcome')?>
Room partials is make a new viewm, this code similiar feature to Rendering view h1.html
<h1>Title For website</h1>
content.html
<?=$room->open('content')?>
<?=$room->include('h1')?>
<?=$room->close()?>
<?=$room->extend('welcome')?>
If you are include a view, the new view will have different data so you can passing data from content.html to h1.html h1.html
<h1><?=$room->data('title')?></h1>
content.html
<?=$room->open('content')?>
<?=$room->include('h1', ['title=>"Title For website"])?>
<?=$room->close()?>
<?=$room->extend('welcome')?>
- More efficient & effective code
- Data conditional rendering
MIT
Email : [email protected]
Instagram : said_nrs
Facebook : https://www.facebook.com/telorjan/
Because my english is so bad, i think i only accept project from indonesian people :(