вот модель
<?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);
}
}
вот контролер
<?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
]);
}
}
}
вот представление films/parser.php
<?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 } ?>