我使用Yii,我得到了这个错误;我应该了解和做什么?
不重复:source或任何其他;
错误发生在:->bindParam(":url_id", $url->id)
$url = Url::model()->findByAttributes(array('link' => $_url));
if (empty($url)) {
$url = new Url();
$url->website_id = $website->id;
$url->link = $_url;
$url->title = '';
$url->description = '';
$url->doctype = $_doctype;
$url->visits = 1;
$url->created = date('Y-m-d h:i:s',time());
$url->updated = date('Y-m-d h:i:s',time());
$url->status = 1;
$url->save(false);
} else {
// update visits
$url->saveCounters(array('visits' => 1));
// url existed, let's load products
if (!Yii::app()->user->isGuest) {
$sql = "select u.id from url as u
left join url_follower as u_f
on u.id = u_f.url_id and u_f.user_id = :user_id
where u.id =:url_id";
$cmd = Yii::app()->db->createCommand($sql)
->bindParam(":url_id", $url->id)
->bindParam(":user_id", Yii::app()->user->id);
$url_id = $cmd->queryScalar();
答案 0 :(得分:3)
经过测试的解决方案:
$user_id = Yii::app()->user->id;
$url_id = $url->id;
$cmd = Yii::app()->db->createCommand($sql)
->bindParam(":user_id", $user_id)
->bindParam(":url_id", $url_id);