コード例 #1
0
ファイル: Base.php プロジェクト: codemix/restyii
 /**
  * Creates a criteria that can be used to return related records
  *
  * @param ActiveRecord $finder the finder model
  *
  * @return \CDbCriteria the criteria object
  * @throws \CHttpException if unknown embedded parameters are specified
  */
 protected function createEmbedCriteria(ActiveRecord $finder)
 {
     $criteria = new \CDbCriteria();
     $criteria->with = array();
     $params = $this->getParams();
     if (isset($params['_embed'])) {
         $embedNames = preg_split("/\\s*,\\s*/", $params['_embed']);
         $links = $finder->links();
         foreach ($embedNames as $name) {
             if (($pos = strpos($name, '.')) !== false) {
                 $first = substr($name, 0, $pos);
             } else {
                 $first = $name;
             }
             if (!isset($links[$first])) {
                 throw new \CHttpException(400, \Yii::t('resource', "Invalid request, unknown {name} parameter.", array('{name}' => $name)));
             }
             if ($name != 'stats') {
                 $criteria->with[] = $name;
             }
         }
         if (count($embedNames)) {
             $criteria->together = true;
         }
     }
     return $criteria;
 }