双主键的Rest怎么搞

Jian
  • 768

数据表的uid,mid字段为双主键,要实现rest怎么搞?

还有别的什么方法吗

回复
阅读 3.2k
1 个回答
✓ 已被采纳

自己解决了,

yii2是用,解决,原本传递id=10的,双主键为id=10,20。

    public function findModel($id)
    {
        if ($this->findModel !== null) {
            return call_user_func($this->findModel, $id, $this);
        }

        /* @var $modelClass ActiveRecordInterface */
        $modelClass = $this->modelClass;
        $keys = $modelClass::primaryKey();
        if (count($keys) > 1) {
            $values = explode(',', $id);
            if (count($keys) === count($values)) {
                $model = $modelClass::findOne(array_combine($keys, $values));
            }
        } elseif ($id !== null) {
            $model = $modelClass::findOne($id);
        }

        if (isset($model)) {
            return $model;
        } else {
            throw new NotFoundHttpException("Object not found: $id");
        }
    }
宣传栏