S
S
Sergey Beloventsev2016-05-04 11:21:04
Yii
Sergey Beloventsev, 2016-05-04 11:21:04

What caused the error Call to a member function getActiveValidators() on a non-object here is the model?

here is the model

<?php
namespace backend\models;

use Yii;
use yii\base\Model;
use common\models\Category;
use common\models\Trailers;
use common\models\UploadImage;
use common\models\Image;
use common\snoopy\Parser;
class Parsers extends Model
{
    public function rules()
    {
        return [
            [['id'], 'integer'],
        ];
    }
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('app','ID_PARSER'),
        ];
    }
    public function addParsers($id){
        $post_array = array(
            'shop_user[login]' => 'dimmduh',
            'shop_user[pass]' => 'gfhjkm03',
            'shop_user[mem]' => 'on',
            'auth' => 'go',
        );
        $snoopy = new Parser($id,$post_array);
        $films = $snoopy->getAll();
        return($films);
    }

}

here is the controller
<?php

namespace backend\controllers;

use Yii;
use common\models\Films;
use app\models\FilmsSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use common\models\Serial;

use backend\models\Parsers;

class FilmsController extends Controller{
    public function actionParser(){
        $parser = new Parsers();
        if ($parser->load(Yii::$app->request->post())){
            $id=Yii::$app->request->post('id');
                $films=$parser->addParsers($id);
                return $this->render('parser', [
                    'snoopy' => $films,
                ]);
        }else{
            return $this->render('parser', [
                'model'     => $parser
        ]);
        }
    }
}

here is the films/parser.php view
<?php
use yii\widgets\ActiveForm;
use yii\helpers\Html;

    if(isset($snoopy)){
        header('Content-Type: text/json; charset=utf-8');
        var_dump($snoopy);
    }else{ ?>
        <div class="pages-form">

    <?php $form = ActiveForm::begin(); ?>
        <?= $form->field($parser, 'id')->textInput(['maxlength' => true]) ?>

        <div class="form-group">
            <?= Html::submitButton( Yii::t('app','CREATE'), [ 'btn btn-primary']) ?>
        </div>

    <?php ActiveForm::end(); ?>
   <?php  } ?>

Answer the question

In order to leave comments, you need to log in

[[+comments_count]] answer(s)
A
Alexander, 2016-05-04
@Sergalas

<?= $form->field($parser, 'id')->textInput(['maxlength' => true]) ?>

replace $parser with $model
or
return $this->render('parser', [
                'model'     => $parser
        ]);

'model' replace with 'parser'

M
Maxim Timofeev, 2016-05-04
@webinar

1. $snoopy = new Parser($id,$post_array); - probably not Parser, but Parsers and I advise you to avoid using the plural when naming classes
2. You pass it to the view model, and use $parser in the form

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question