2

In yii I had such code which was roking OK

$form=$this->beginWidget('CActiveForm', array(
    'id'=>'ride-form',
    'enableClientValidation'=>false,
    'clientOptions'=>array(
        'validateOnSubmit'=>true,
    ),
));

now I am trying to use it in Yii 2 version. But I'm getting error

Calling unknown method: yii\web\View::beginWidget()

Why ? and what class maybe I should additionally use to fix this problem ?

4

2 回答 2

1

This error appears because yii\web\View class simply does not have the method beginWidget().

For working with forms in Yii2 use ActiveForm widget.

Replace your code with:

use yii\widgets\ActiveForm;    

$form = ActiveForm::begin([
    'id' => 'ride-form',
    'enableClientValidation'=>false,
    'validateOnSubmit' => true, // this is redundant because it's true by default
]);

// ...

ActiveForm::end();
于 2014-12-18T13:09:25.557 回答
0

2 things i would check for if a method is unknown.

1) is the class included before you call it?

2) Are you creating an instance of the class and calling the class from that instance variable?

include 'myClass.php';

$class = new myClassName();

$class->method();
于 2014-12-18T13:07:16.463 回答