Beispiel #1
0
 public function renderKeys()
 {
     echo CHtml::openTag('div', array('class' => 'keys', 'style' => 'display:none', 'title' => Yii::app()->getRequest()->getUrl()));
     foreach ($this->dataProvider->getKeys() as $key) {
         echo "<span>" . CHtml::encode($key) . "</span>";
     }
     echo "</div>\n";
 }
 /**
  * Returns the key values associated with the data items.
  * @param boolean $refresh whether the keys should be re-calculated.
  * @return array the list of key values corresponding to {@link data}. Each data item in 
  *   {@link data}
  * is uniquely identified by the corresponding key value in this array.
  */
 public function getKeys($refresh = false)
 {
     /* x2modstart */
     if ($this->calculateChecksum && $refresh) {
         throw new CException('refresh cannot be called if calculcateChecksum is set to true');
     }
     /* x2modend */
     return parent::getKeys($refresh);
 }
Beispiel #3
0
	/**
	 * Lists all models.
	 */
	public function actionBoard($slug) {
		if (!$slug)
			throw new CHttpException(404, 'The requested board does not exist.');
		$board=Yii::app()->cache->get($slug);
		if ($board===false) {
			$board=Board::model()->find('slug=:slug', array(':slug'=> $slug));
			if ($board)
				Yii::app()->cache->set($slug, $board, 2592000); // 1 month
			else
				throw new CHttpException(404, 'The requested page does not exist.');
		}
		$this->pageTitle=Yii::app()->name." - ".$board->name;
		$model=new Post;
		$model->board=$board->id;
		if (isset($_POST['Post'])) {
			$model->attributes=$_POST['Post'];
			$model->image=CUploadedFile::getInstance($model, 'image');
			$name=time() . rand(10, 90);
			if ($model->image)
				$model->filename=$board->slug . "/" . $name . "." . $model->image->getExtensionName();
			if ($model->save()) {
				$this->uploadImage($name, $board->slug, $model);
				$model->addReplies();
				$this->redirect(array('thread', 'slug'=> $board->slug, 'id'=> $model->vid));
			}
		}

		$notmain=isset($_GET['Post_page']);
		$dataProvider=Yii::app()->cache->get('board' . $board->slug);
		if ($notmain || $dataProvider===false) {
			$dataProvider=new CActiveDataProvider('Post', array(
						'criteria'=> array(
							'condition'=> 'board=:boardId AND parent_id=0',
							'params'=> array(':boardId'=> $board->id),
							'order'=> 'updated DESC',
						),
					));
			// attach replies, need find more correct way
			Post::addLastReplies($dataProvider->getData());
			$dataProvider->getKeys(); // wtf? without this before set cache we get error
			if(!$notmain)
				Yii::app()->cache->set('board' . $board->slug, $dataProvider, 86400); // 1 day
		}
		$this->render('board', array(
			'dataProvider'=> $dataProvider,
			'model'=> $model,
			'board'=> $board,
		));
	}