model() public static method

Returns the static model of the specified AR class.
public static model ( string $className = __CLASS__ ) : ImageToGallery
$className string
return ImageToGallery the static model class
コード例 #1
0
ファイル: DefaultController.php プロジェクト: RSol/yupe
 public function actionDeleteImage($id)
 {
     if (Yii::app()->request->isPostRequest) {
         ImageToGallery::model()->findByPk((int) $id)->delete();
         if (!isset($_GET['ajax'])) {
             $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));
         }
     } else {
         throw new CHttpException(400, 'Invalid request. Please do not repeat this request again.');
     }
 }
コード例 #2
0
 /**
  * Отображение изображений галереи:
  *
  * @param int $id - id-галереи
  *
  * @return void
  **/
 public function actionImages($id)
 {
     if (($gallery = Gallery::model()->findByPk($id)) === null) {
         throw new CHttpException(404, Yii::t('GalleryModule.gallery', 'Page was not found!'));
     }
     $image = new Image();
     if (Yii::app()->getRequest()->getIsPostRequest() && ($imageData = Yii::app()->getRequest()->getPost('Image')) !== null) {
         $this->_addImage($image, $imageData, $gallery);
     }
     $criteria = new CDbCriteria();
     $criteria->condition = 't.gallery_id = :gallery_id';
     $criteria->order = 't.position';
     $criteria->with = 'image';
     $criteria->params = [':gallery_id' => $gallery->id];
     $this->render('images', ['dataProvider' => ImageToGallery::model()->findAll($criteria), 'image' => $image, 'model' => $gallery, 'tab' => !($errors = $image->getErrors()) ? '_images_show' : '_image_add']);
 }