Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8538597
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:09:19+00:00 2026-06-11T11:09:19+00:00

Yii CMS I have a unique composite key in the table ‘category’, website_id +

  • 0

Yii CMS

I have a unique composite key in the table ‘category’, website_id + link, and Yii does not support this keys, so I wrote my own method

a website has many links, each unique;
2 or more websites may have the same link; because the link may not be absolute;

from a array of links, I extract one link at a time, and if the category pattern fits, I want to store the 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();
}

and the method

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;

}

and the error returned :

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)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T11:09:20+00:00Added an answer on June 11, 2026 at 11:09 am

    I believe you should be able to allow Yii to handle the composite key by adding the following to your model:

    public function primaryKey()
    {
        return array('website_id','link');
    }
    

    EDIT,

    Sorry, misread your question! For unique keys (not primary) you could try these extensions:

    http://www.yiiframework.com/extension/composite-unique-key-validatable/

    http://www.yiiframework.com/extension/unique-index-validator

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing a CMS using Yii Framework. In developing the theme I have a
in my YII form i have a dropdown depending on a table to another
I have a Yii query: $criteria->select = 't.baniid,SUM(t.impression) AS impression, SUM(t.`unique`) AS `unique`, IFNULL((SELECT
Using Yii framework. I have 3 models. Articles - table articles(id, name) ArticlesToAuthors -
I'm using yii active records for mysql , and i have a table where
We have an Yii-based PHP application which does some generic actions (like Share with
My Yii code not showing error summery before save movie in database.. what's the
I'm new using Yii framework. I show a list a checkbox. But it's not
In a YII work, I have an init() function which checks whether the session
I am using YII framework for my web application . I have a question

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.