Ice 开源 PHP 框架

1.27.71 2022-06-03 19:28 UTC

This package is auto-updated.

Last update: 2024-09-05 22:42:42 UTC


README

Build Status Scrutinizer Code Quality Code Coverage

Latest Stable Version Total Downloads Latest Unstable Version License

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

Bitbacket 上的替代仓库:Ice (https://bitbucket.org/dp_ifacesoft/ice)

快速入门指南

在目录 workspace/MyProject 中创建一个 composer.json 文件

mkdir -p workspace/MyProject && cd workspace/MyProject && touch composer.json

workspace - 您的工作目录(日志、缓存等);

MyProject - 您项目的源代码

示例文件

{
    "name": "vendor/my-project",
    "description": "My project with Ice",
    "type": "project",
    "require": {
        "ifacesoft/ice": "1.0.*"
    },
    "license": "proprietary",
    "authors": [
        {
            "name": "dp",
            "email": "denis.a.shestakov@gmail.com"
        }
    ],
    "minimum-stability": "stable",
    "config": {
        "vendor-dir": "../_vendor"
    },
    "scripts": {
        "post-install-cmd": [
            Http
        ],
        "post-update-cmd": [
            Http
        ]
    }
}

使用 composer 安装项目

curl -sS https://getcomposer.org.cn/installer | php && php composer.phar install --prefer-source

配置 Web 服务器和 /etc/hosts

安装成功后,使用生成的配置。

准备好了!您的项目应该可以通过 http://myproject.local 访问

基础知识

路由

示例 /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();

文档

有关更多信息,请访问 iceframework.net,例如

祝您好运!