Skip to content

ichsansaid/Codeigniter3-RoomLibrary

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 

Repository files navigation

CodeIgniter 3 Room Library

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 !

Documentation

Declare a 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 .

Extend a view

<?=$room->extend('welcome')?>

You must put the extend after all room has opened

Open & close Room

<?=$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')?>

Rendering the view with Room

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);
}

Access data in room

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')?>

Including room partials

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')?>

Todos

  • More efficient & effective code
  • Data conditional rendering

License

MIT

Don't hesitate to contact me if you need help

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 :(

About

This library similiar to View Layouts in Codeigniter4

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages