PHPackages                             yllumi/ci4-pages - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. yllumi/ci4-pages

ActiveLibrary[Framework](/categories/framework)

yllumi/ci4-pages
================

Page based router for CodeIgniter 4

v1.0.7(1y ago)51.3k11MITPHPPHP ^8.1CI failing

Since Dec 27Pushed 1y ago1 watchersCompare

[ Source](https://github.com/yllumi/ci4-pages)[ Packagist](https://packagist.org/packages/yllumi/ci4-pages)[ RSS](/packages/yllumi-ci4-pages/feed)WikiDiscussions main Synced 3w ago

READMEChangelog (8)Dependencies (5)Versions (14)Used By (1)

ci4-pages
=========

[](#ci4-pages)

[![tests build](https://github.com/yllumi/ci4-pages/workflows/tests%20build/badge.svg)](https://github.com/yllumi/ci4-pages/workflows/tests%20build/badge.svg)

**ci4-pages** is a package for CodeIgniter 4 that provides a **page-based routing mechanism**. This package simplifies routing management with a file-based and folder-structured approach, making it suitable for projects requiring dynamic routing. Think of it as similar to Next.js or Laravel Folio but maintaining the coding style unique to CodeIgniter 4.

Installation
------------

[](#installation)

Install this package via Composer with the following command:

```
composer require yllumi/ci4-pages
```

Configuration
-------------

[](#configuration)

Register the pageview\_helper in **`app/Controllers/BaseController.php`**

```
protected $helpers = ['Yllumi\Ci4Pages\Helpers\pageview'];
```

Usage
-----

[](#usage)

Create a folder named `app/Pages/`. This folder will be used to store all your page controller files.

```
app/
├── Pages/
│   ├── home/
│   │   ├── PageController.php
│   │   ├── index.php
│   ├── profile/
│   │   ├── PageController.php
│   │   ├── index.php
│   │   ├── achievement/
│   │   │   ├── PageController.php
│   │   │   ├── index.php

```

Each folder inside `app/Pages/` will represent a page route. For example, the folder `app/Pages/home` will be accessible at `domain.com/home`. Similarly, the folder `app/Pages/profile/achievement/` will be accessible at `domain.com/profile/achievement/`.

There is one mandatory file that must exist in the pages folder, namely PageController.php, which will handle page requests. Besides that, you can create other .php files for views and so on.

Let's look at an example code below:

**`app/Pages/home/PageController.php`**

```
!
Selamat berkarya dengan CodeIgniter!
```

In the example above, we created two files. The first is `PageController.php`, a controller class with one method `getIndex()`. This method handles requests to mydomain.com/home or mydomain.com/home/index.

The `getIndex()` method can have parameters that capture the URI segment after the page segment. For instance, in the example above, you can call domain.com/home/Toni or domain.com/home/index/Toni, where the string 'Toni' will be received by the `$name` parameter of the `getIndex()` method.

In the example above, the `getIndex()` method returns the output of the `pageView()` function. This function is similar to `view()` in CodeIgniter but is adjusted to accept the path of the view file located under the app/Pages/ folder. `return pageView('home/index', $data);` means it returns the view file app/Pages/**home/index**.php.

In addition to the `getIndex()` method, you can also create other methods i.e. `getDetail()` or `postInsert()`. Only methods whose names start with an HTTP verb can handle HTTP requests. The method naming mechanism in this controller is the same as the Auto Route (improved) provided by CodeIgniter 4. Method `getDetail()` for example, can be accessed from mydomain.com/home/detail/\[id\].

#### API Endpoint

[](#api-endpoint)

You can also return RESTful responses by adding the ResponseTrait to the controller class.

**`app/Pages/home/PageController.php`**

```
