lan/ice-fork

Ice开源PHP框架

1.30.9 2024-07-10 08:17 UTC

This package is auto-updated.

Last update: 2024-09-10 09:37:10 UTC


README

Ice是一个通用PHP框架。在开发复杂Web应用程序时,您可以完全信赖Ice。Ice的关键特性包括主要组件的内置缓存支持、灵活的配置以及轻松扩展现有功能的能力。

基本内容

路由

示例 /config/Ice/Core/Route.php

<?php
return [
    'mp_page' => [
        'route' => '/page/{$page}',
        'params' => [
            'page' => '(\d)'
        ],
        'weight' => 10000,
        'request' => [
            'GET' => [
                'Www:Layout_Main' => [
                    'actions' => [
                        ['Ice:Title' => 'title', ['title' => 'Ice - Open Source PHP Framework ']],
                        'Www:Index' => 'main'
                    ]
                ]
            ]
        ]
    ]
]    

重要部分

  • 'mp_page' - 路由名称,(使用:Route::getInstance('mp_page') -> getUrl(20)) 返回 '/page/20' 等.)
  • 'weight' - 匹配路由的优先级。权重越大,优先级越高。
  • 'request' 部分 - 可用请求方法数组(GET、POST等)
  • 'request/GET' - 只有一个项目(第一个)包含布局动作类作为键和参数作为值

动作

namespace Mp\Action;
use Ice\Core\Action;
class Page extends Action
{
    protected static function config()
    {
        return [
            'view' => ['viewRenderClass' => 'Ice:Smarty', 'template' => null, 'layout' => null],
            'actions' => [],
            'input' => [],
            'output' => [],
            'cache' => ['ttl' => -1, 'count' => 1000],
            'access' => [
                'roles' => [],
                'request' => null,
                'env' => null
            ]
        ];
    }
    public function run(array $input)
    {
    }
}

2个主要方法 - 配置和运行

方法 config - 返回数组

  • 'view' - 定义输出数据的渲染方式('viewRenderClass' - 渲染类,'template' - 渲染模板,layout - 渲染内容的emmet样式模板包装器)
  • 'actions' - 子动作
  • 'input' - 输入参数数组及其数据提供者。还包括验证器、默认值和其他信息。
  • 'output' - 额外的输出源(参数及其数据提供者以及'input'部分)
  • 'ttl' - 缓存中存储的时间(目前只支持3600 :) )
  • 'access' - 检查运行动作的权限的信息(支持环境 - 'production'、'test' 或 'development' 之一和请求 - 'cli' 或 'ajax' 之一)

模型

选择示例

// 1.
$page = Page::getModel(20, ['title', 'desc']); // or Page::getModel(20, '*')
// 2.
$page = Page::create(['title' => 'page 20')->find([id, 'desc']);
// 3.
$page = Page::createQueryBuilder()->eq(['desc' => '20th page'])->getSelectQuery()->getModel();

插入示例

// 1. 
Page::create(['title' => 'page 20', 'desc' => '20th page'])->save();
// 2.
Page::createQueryBuilder()->getInsertQuery(['title' => 'page 20', 'desc' => '20th page'])->getQueryResult();

更新示例

// 1. 
Page::getModel(20, ['title', 'desc'])->set(['title' => 'another title'])->save();
// 2.
Page::createQueryBuilder()->eq(['id' => 20])->getUpdateQuery(['title' => 'another title'])->getQueryResult();

更新示例

// 1. 
Page::getModel(20, '/pk')->remove();
// 2.
Page::createQueryBuilder()->getDeleteQuery(20)->getQueryResult();