yii-入门资料

yii-2

控制器与URL

controler\ 目录下存放控制器

<?php
namespace app\controllers;

use yii\web\Controller;


class TestController extends Controller
{
public function actionIndex()
{
echo 'me create Controller success!';
}
public function actionUserIndex()
{
echo '方法名是用大写区分的';
}
}

访问自己创建的控制器

URL: http://{{域名}}/index.php?r=test/index :: 不能大写

URL:http://{{域名}}/index.php?r=test/user-index :: 使用-分隔

linux安装YII2

使用composer安装

1.安装comoposer(如果已经安装 更至最新 composer self-update)
curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer

2.使用composer安装YII需要的组件及框架

composer global require "fxp/composer-asset-plugin:^1.3.1"
composer create-project --prefer-dist yiisoft/yii2-app-basic basic

3.测试安装结果

php yii serve --port=8888 #此种方式只能本机访问
http://127.0.0.1:8888 

Continue reading “linux安装YII2”