deesoft/yii2-angular

Yii2 angular 扩展

安装次数:49,693

依赖项: 3

建议者: 0

安全性: 0

星标: 45

关注者: 13

分支: 17

开放问题: 6

类型:yii2-extension

1.3 2015-09-03 14:43 UTC

This package is not auto-updated.

Last update: 2024-09-14 17:06:01 UTC


README

Yii2 angular 扩展

安装

安装此扩展的首选方式是通过 composer

运行以下命令之一

php composer.phar require deesoft/yii2-angular "~1.0"

或者将以下内容添加到您的 composer.json 文件的 require 部分。

"deesoft/yii2-angular": "~1.0"

使用方法

在视图文件中

<?php
use dee\angular\NgView;

/* @var $this yii\web\View */
?>

<?= NgView::widget([
    'name' => 'myapp', // default dApp
    'routes'=>[
        '/'=>[
            'view' => 'index',
            'js' => 'index.js',
        ],
        '/view/:id'=>[
            'view'=>'view', 
            'js'=>'view.js',
            'injection'=>['$location', '$routeParams'], // $scope and $injector are always be added              
        ],
        '/edit/:id'=>[
            'view'=>'edit',
        ],
        '/create'=>[
            'view'=>'create',
        ],
    ]
])?>

然后是 index.php

<?php

use dee\angular\NgView;

/* @var $this yii\web\View */
/* @var $widget NgView */
?>

<ul>
    <li ng-repeat="item in items">
        <a ng-href="/view/{{item.id}}">{{item.name}}</a>
    </li>
</ul>

index.js

Rest = $injector.get('Rest');

query = function(){
    Rest.query({},function(r){
        $scope.items = r;
    });
}

$scope.deleteItem = function (id) {
    Rest.remove({id:id},{},function(){
        query();
    });
}

使用 GII 生成 CRUD

安装 deesoft/yii2-gii 然后添加配置

...
if (!YII_ENV_TEST) {
//     configuration adjustments for 'dev' environment
    $config['bootstrap'][] = 'debug';
    $config['modules']['debug'] = 'yii\debug\Module';

    $config['bootstrap'][] = 'gii';
    $config['modules']['gii'] = [
        'class' => 'yii\gii\Module',
        'generators' => [
            'angular' => ['class' => 'dee\gii\generators\angular\Generator'],
        ]
    ];
}