model() public static method

public static model ( null | string $className = __CLASS__ )
$className null | string
Exemplo n.º 1
0
 /**
  * @param $id
  * @return Export
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = Export::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, Yii::t('YmlModule.default', 'Page not found!'));
     }
     return $model;
 }
Exemplo n.º 2
0
 public function actionView($id)
 {
     $model = Export::model()->findByPk($id);
     if (false === $model) {
         throw new CHttpException(404);
     }
     $criteria = new CDbCriteria();
     $criteria->compare('t.status', Product::STATUS_ACTIVE);
     if (!empty($model->categories)) {
         $criteria->addInCondition('t.category_id', (array) $model->categories);
     }
     if (!empty($model->brands)) {
         $criteria->addInCondition('t.producer_id', (array) $model->brands);
     }
     $dataProvider = new CActiveDataProvider('Product', ['criteria' => $criteria]);
     $offers = new CDataProviderIterator($dataProvider, 100);
     ContentType::setHeader(ContentType::TYPE_XML);
     $this->renderPartial('view', ['model' => $model, 'currencies' => Yii::app()->getModule('store')->getCurrencyList(), 'categories' => StoreCategory::model()->published()->findAll(), 'offers' => $offers]);
 }
Exemplo n.º 3
0
 public function actionView($id)
 {
     /* @var $model Export */
     $model = Export::model()->findByPk($id);
     if (!$model) {
         throw new CHttpException(404);
     }
     $cacheKey = $this->cacheKey . $model->id;
     if (!($xml = Yii::app()->getCache()->get($cacheKey))) {
         $xml = $this->getXmlHead();
         $xml .= CHtml::openTag('yml_catalog', ['date' => date('Y-m-d H:i')]);
         $xml .= CHtml::openTag('shop');
         $xml .= $this->getShopInfo($model->shop_name, $model->shop_company, $model->shop_url ?: Yii::app()->getBaseUrl(true), $model->shop_platform, $model->shop_version, $model->shop_agency, $model->shop_email, $model->shop_cpa);
         $xml .= $this->getCurrenciesElement([['id' => 'RUR', 'rate' => 1]]);
         $xml .= $this->getCategoriesElement();
         $xml .= $this->getOffersElement($model->categories, $model->brands);
         $xml .= CHtml::closeTag('shop');
         $xml .= CHtml::closeTag('yml_catalog');
         Yii::app()->getCache()->set($cacheKey, $xml, 60 * 60);
     }
     header("Content-type: text/xml");
     echo $xml;
     Yii::app()->end();
 }