Yii CMS
テーブル 'category'、website_id + link に一意の複合キーがあり、Yii はこのキーをサポートしていないため、独自のメソッドを作成しました
Web サイトには、それぞれ固有の多数のリンクがあります。2 つ以上の Web サイトが同じリンクを持っている場合があります。リンクは絶対的ではない可能性があるためです。
リンクの配列から一度に 1 つのリンクを抽出し、カテゴリ パターンが適合する場合は、URL を保存します。
preg_match('/\/popular\/(.*?)\/1\.html/ims', $matches_website_url[1], $matches_url);
if(count($matches_url) > 0 &&
    $this->avoid_duplicate_category($website['id'], $matches_url[1]) )
{
    $category = new Category();
    $category->website_id = $website['id'];
    $category->link = $matches_url[0];
    $category->name = $matches_url[1];
    $category->urls = 0;
    $category->update = time();
    $category->save();
}
と方法
private function avoid_duplicate_category($website_id,$link)
{
    $query_category = Yii::app()->db->createCommand("select * from `category` where `website_id`='.$website_id.' and `link`='.$link.';");
    $results = $query_category->queryAll();
    if(count($results)>0)return false;
    else return true;
}
エラーが返されました:
CDbException
CDbCommand failed to execute the SQL statement: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'Cute' for key 'name'. The SQL statement executed was: INSERT INTO `category` (`website_id`, `link`, `name`, `urls`, `update`) VALUES (:yp0, :yp1, :yp2, :yp3, :yp4)