木子炜培先生

⑴2017底=>(年薪15万)=>31岁 ⑵2018=》(生产生活用品)并且年薪20万=>32岁 ⑶2019=>年薪30万=>把小作坊升级为工厂=>33岁 ⑷2020=>再开一个食品工厂

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

1在frontend/libs新建TestAction.php

<?php
namespace frontend\libs;
use yii\base\Action;
class TestAction extends Action {
    public $param1=NULL;
    public $param2=NULL;
    public function run($get=NULL) {
        return $this->controller->render('test',[
            'get'=>$get,
            'param1'=>$this->param1,
            'param2'=>$this->param2
        ]);
    }
}

2在SiteController里调用testAction:

  public function actions()
    {
        return [
            'error' => [
                'class' => 'yii\web\ErrorAction',
            ],
            'captcha' => [
                'class' => 'yii\captcha\CaptchaAction',
                'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
            ],
            'test'=>[
                'class'=>'frontend\libs\TestAction',
                'param1'=>'参数一',
                'param2'=>'参数二',
            ]
        ];
    }

3配置视图views/site/test.php完成测试:

<h1>TestAction</h1>
<p>这是TestAction演示页面!</p>
<p>$get="<?=$get?>"</p>
<p>$param1="<?=$param1?>"</p>
<p>$param2="<?=$param2?>"</p>

http://127.0.0.8/index.php?r=site%2Ftest&get=xxx

 

$get、$param1、$param2,其中$get是在url中传递的,例如按照我电脑上的配置,访问http://127.0.0.8/index.php?r=site%2Ftest&get=xxx,就会为$get赋值xxx。而$param1和$param2则是在controller中设置的。

posted on 2017-01-29 12:04  木子炜培先生  阅读(335)  评论(0编辑  收藏  举报