【问题标题】:The system is unable to find the requested action "name1". in yii how to solve it [closed]系统找不到请求的操作“name1”。在yii中如何解决它[关闭]
【发布时间】:2013-10-11 07:05:29
【问题描述】:

它的控制器文件

class NameFormController extends Controlle
{
    public function actionCreate()

    {
        $model = new NameForm;
        if(isset($_POST['NameForm']))

        {
            $model->attributes=$_POST['NameForm'];
            $model->save();

            }
        $this->render('index' ,array('model'=> $model));
    }

}

它的模块文件

class NameForm extends CActiveRecord
{
    public $name;

    public function tableName()
    {
        return 'name' ;
    }


    public function rules()
    {
            return array('name','required');
    }

    public function attributeLabels()
    {
        return array
        ('id'=>'ID',
          'name'=>'Name'
        );
        }
        public static function model($className=__CLASS__)
    {
        return parent::model($className);
    }

} 

【问题讨论】:

  • 没有名为“name1”的操作。

标签: php yii


【解决方案1】:

NameFormController 应该扩展自 Controller,而不是 Controlle

在你的NameFormController,添加函数:

public function actionName1() {
    echo 'action Name1()';
}

不要忘记更新访问规则以允许访问您的新操作:

public function accessRules() {
    return array(
        array('allow',
            'actions' => array('index', 'view', 'name1'),
            'users' => array('*'),
        ),
        array('deny',
            'users' => array('*'),
        ),
    );
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-04-28
    • 2011-01-02
    • 2018-10-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-25
    • 1970-01-01
    相关资源
    最近更新 更多