cst/yii-illuminate

此包已被弃用且不再维护。未建议替代包。

连接到Laravel的强大功能

1.0.2 2016-10-06 14:29 UTC

This package is not auto-updated.

Last update: 2021-03-27 15:41:15 UTC


README

此包简化了与某些Laravel组件的集成

要求

以下版本的PHP受到支持。

  • PHP 5.6
  • HHVM(未测试)

安装

您可以使用Composer包管理器安装此包。您可以在项目根目录中运行以下命令来安装它

composer require cst/yii-illuminate

组件

迁移命令

通过Laravel Schema Builder的所有功能增强Yii的MigrateCommand

将以下块添加到您的配置文件中

'commandMap'=> [
    'migrate'=> [
        'class' => '\CST\Yii\Illuminate\Console\MigrateCommand',
        'migrationTable' => 'yii_migrations',
        'connectionID' => 'db',
    ],
],

队列

队列允许您将耗时的任务(如发送电子邮件)推迟到以后处理,从而显著加快对应用程序的Web请求。

RedisQueue

将以下块添加到您的配置文件中

'queue' => [
    'class' => '\CST\Yii\Illuminate\Queue\RedisQueue',
    'encryptionKey' => '<random-string-of-16bytes>',
    'config' => [
        'cluster' => false,
        'default' => [
            'host'     => '<HOST>',
            'port'     => 6379,
            'database' => 0,
        ],
    ]
],

配置队列命令

将以下块添加到您的配置文件中

'commandMap'=> [
    ...,
    'queue'=> [
        'class' => '\CST\Yii\Illuminate\Console\QueueCommand',
    ],
],

排队作业

Yii::app()->queue->push(new SendEmail($message));

或者

use CST\Yii\Illuminate\Queue\DispatchesJobs;

$this->dispatch(new SendEmail($message));

辅助函数

app(string $component = null)

获取Yii App实例。它是Yii::app()的快捷方式。您还可以传递组件名称以获取其实例。

app('clientScript')->registerScriptFile(...);
t(string $category, string $message, array $params = [], string $source = null, string $language = null)

Yii::t()用于翻译消息的快捷方式。

t('Project', 'Save changes');
view(string $path, array $data, bool $return)

为给定的视图渲染评估后的视图内容。替代了典型的$this->render(...)

view('user/view', ['user' => $user]);
viewPartial(string $path, array $data, bool $return)

为给定的视图渲染评估后的视图内容,但不应用于渲染结果的布局。替代了典型的$this->renderPartial(...)

viewPartial('user/pic', ['user' => $user]);
request(string $key, $default = null)

获取当前请求的实例或请求中的输入项。

$modelId = request('id')
asset(string $path)

为应用程序主题生成资产路径。

asset('js/main.js');
asset('images/logo.png');
url(string $path, array $parameters, bool $secure)

为应用程序生成URL。

url('project/view', ['id' => 1]);