承接 yllumi/ci4pageroute 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

yllumi/ci4pageroute

Composer 安装命令:

composer require yllumi/ci4pageroute

包简介

Page based routing for CodeIgniter 4

README 文档

README

Develop even more rapid with page based route. It is like Nextjs or Nuxtjs for CodeIgniter 4.

Install

  • Install CodeIgniter 4
  • Run composer composer require yllumi/ci4pageroute
  • Change 2 line of Config/Routes.php in CodeIgniter like this:
    $routes->set404Override('\Yllumi\Pager\Controllers\Page::index');
    $routes->get('/', '\Yllumi\Pager\Controllers\Page::index');
  • Run composer run -d vendor/yllumi/ci4pageroute add-sample-page to place sample pages
  • Happy develop!

Create Page

Page based route use Latte template engine to build page structure.

By default page is placed inside folder pages/ in root project.

project/
  app/
  pages/
    index.html
    meta.yml
  public/
  test/
  vendor/
  writable/

To make the page work, you must create at least two files, meta.yml and index.html. meta.yml is used to define page properties and index.html is the page template itself.

For example, create meta.yml inside folder pages/ like this:

page_title: Home

and create index.html in the same place:

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>{$page_title}</title>
</head>
<body>
  <h1>Welcome!</h1>
</body>
</html>

You can then call your app in browser and the root homepage will show those page files.

Write PHP Operation

You also can write any PHP code just like you do in controller by creating file Action.php in the same place, with this structure:

<?php

class PageAction {

  // This method handle get request
  public function run()
  {
    $data['intro'] = '<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Aliquam voluptate error laboriosam ullam odio quasi repellendus minus provident. Amet dolores repellat doloremque, nemo similique officia molestias quaerat sequi, voluptates rerum.</p>';

    return $data; 
  }


  // This method handle POST request
  public function process(){

  }

}

Every data inside $data variable you return can be called inside page template as like you do with any properties from meta.yml.

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>{$page_title}</title>
</head>
<body>
  <h1>Welcome!</h1>
  <p>{$intro|noescape}</p>
</body>
</html>

There are at least two method inside PageAction class, run() and process(). Method run() is used to write code to handle GET request of the page, and process() is used to handle POST request to that page.

Create Subpage

You can also create any subpage by creating subfolder inside pages/. You can then place meta.yml, index.html, and Action.php inside that subfolder.

pages/
  about/
    index.html
    meta.yml
  index.html
  meta.yml

The above page structure results pages http://domain.test/ and http://domain.test/about.

统计信息

  • 总下载量: 8
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-10-23

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固