When writing a parser, I need to compare whether there is already such a url in the database, and if not, then parse it and then the content via this link. I try to use exist with the basic configuration of Yii2, but the campaign turns out to be some kind of Hindu-Chinese non-working code. It does not work for me to exist properly. Can someone tell me how to use it correctly.

foreach ($links_get as $link_get){ $url = pq($link_get)->find('.titles h3 a')->attr('href'); if (strpos($url, 'http://') === 0) { $site_url = $url; } else{ $site_url = $site . $url; } if(!News::find()->where( [ 'url' => $site_url ] )->exists()) { $img = pq($link_get)->find('img')->attr('src'); $text = pq($link_get)->find('.rightcol')->html(); $title = pq($link_get)->find('.titles a>span')->html(); $i++; $mas[$i] = array('title' => $title, 'img' => $img, 'text' => $text, 'site_url' => $site_url, ); } } } return $mas; 
  • It will be more reliable to search for MD5 from url. - ilyaplot
  • As an option to make the field unique to write everything and just work out the errors. - E_p

0