https://packagist.org
Use
php composer.char require yiisoft/yii2-gii 2.0.4
Use
php composer.char install
Edit
Use
php composer.phar global require "fxp/composer-asset-plugin:^1.2.0"
Use
php composer.char create-project yiisoft/yii2-app-basic
composer config -g repo.packagist composer https://packagist.phpcomposer.com
composer.json
配置文件:打开命令行窗口(windows用户)或控制台(Linux、Mac 用户),进入你的项目的根目录(也就是 composer.json
文件所在目录),执行如下命令:
composer config repo.packagist composer https://packagist.phpcomposer.com
上述命令将会在当前项目中的 composer.json
文件的末尾自动添加镜像的配置信息(你也可以自己手工添加):
"repositories": {
"packagist": {
"type": "composer",
"url": "https://packagist.phpcomposer.com"
}
}
Use
url地址?r=debug
Use
http://frontend.hyii2.com/debug/default/index
Edit
public function actionIndex()
{
Yii::beginProfile('profile1');
$cookies = Yii::$app->response->cookies;
$cookies->add(new Cookie(['name'=>'user','value'=>'张三']));
echo $cookies->getValue('users'),'20';
sleep(1);
Yii::EndProfile('profile1');
}
Result
Use
http://frontend.hyii2.com/gii
Edit
['id','title'],
'scenario1'=>['id'],
];
return array_merge(parent::scenarios(), $scenarios);
}
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['title'], 'required'],
[['title'], 'string', 'max' => 255],
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'title' => 'title',
];
}
}
namespace frontend\controllers;
use Yii;
use frontend\controllers\base\BaseController;
use frontend\models\CurdForm;
class CurdController extends BaseController
{
public function actionIndex()
{
$curd = new CurdForm;
$curd->scenario = 'scenario1';
$testData = [
'data'=>['id'=>1,'title'=>'hello world!'],
];
// 加载数据到对象中
$curd -> load($testData,'data');
echo $curd->id;
echo $curd->title;
}
}
Result
Use
frontend/controllers/CurdController.php
Edit
render('index'); // 如果用这个会使用到默认布局 除非使用新布局
return $this->renderPartial('index'); // 不加载任何布局
}
}
Use
common/widgets/TopMenu.php
Edit
namespace common\widgets;
use \yii\base\Widget;
class TopMenu extends Widget
{
public function init(){
parent::init();
echo '';
}
public function run(){
echo '
';
}
public function addMenu($menuText){
return ''.$menuText.' ';
}
}
Use
frontend/views/curd/index
Edit
=$Menu->addMenu('menu1');?>
=$Menu->addMenu('menu2');?>
Result
=$Menu->addMenu('menu1');?>
=$Menu->addMenu('menu2');?>