Answer the question
In order to leave comments, you need to log in
Why are methods of connected class not visible in Yii2?
You need to create a controller for parsing in Yii2. Connected the Simple HTML DOM parser library. But for some reason it does not see the find methods. I can't figure out why.
<?php
namespace app\controllers;
use keltstr\simplehtmldom\SimpleHTMLDom;
use yii\web\Controller;
class ParseController extends Controller
{
public $news;
public function actionParse($sel_from,$sel_as,$url,$how_many_news)
{
$html = SimpleHTMLDom::file_get_html($url);
$i='0';
foreach ($html->find($sel_from) as $article)
{
$this->news=$article->find($sel_as,0)->innertext;
$i++;
if ($i == $how_many_news) break; // прерывание цикла
}
return $this->news;
}
}
Answer the question
In order to leave comments, you need to log in
I guess there is an error here.
The find method is Active Query , not AR. in short, he takes nothing into himself. Specify the conditions and add the number.
//Так
Some::find()->where(['id'=> $model->id])->one();
//Или так
Some::find()->where(['id'=> $model->id])->all();
//Либо использовать полноценные AR findAll и findOne
But for some reason it does not see the find methods. I can't figure out why.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question