yii actions 使用

首先创建一个model   TestAction

<?php
namespace app\models\common;



use yii\base\Action;

class TestAction extends Action
{
    public $name1='1';
    public $name2='2';
    public $name3='3';

    public function run()
    {
        echo $this->name1.$this->name2.$this->name3;
    }
}

?>

创建一个控制器 TestController

<?php

namespace app\controllers;

class TestController extends Controller
{
    public function actions()
    {
        return [
            'test' => [
                'class' => 'app\models\common\TestAction',// 将这个方法映射过来
                'name1' => 'hello',
                'name2' => 'world',
                'name3' => '123',
            ],
        ];
    }

然后访问index.php?r=test/test

猜你喜欢

转载自blog.csdn.net/weixin_43310339/article/details/86591013