A
A
alxsmrn2016-05-15 11:43:14
Yii
alxsmrn, 2016-05-15 11:43:14

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

2 answer(s)
A
Anton Natarov, 2016-05-15
@alxsmrn

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

E
Elena Stepanova, 2016-05-16
@Insolita

But for some reason it does not see the find methods. I can't figure out why.

in what sense "does not see" - count($html->find($sel_from)) what does it return?
$html = SimpleHTMLDom::file_get_html($url); - you directly pull url? is there a result in $html?
or does not see the methods in the sense that the autocomplete does not work?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question