本文整理汇总了PHP中Board::model方法的典型用法代码示例。如果您正苦于以下问题:PHP Board::model方法的具体用法?PHP Board::model怎么用?PHP Board::model使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Board
的用法示例。
在下文中一共展示了Board::model方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: loadModel
/**
* Returns the data model based on the primary key given in the GET variable.
* If the data model is not found, an HTTP exception will be raised.
* @param integer the ID of the model to be loaded
*/
public function loadModel($id)
{
$model=Board::model()->findByPk((int)$id);
if($model===null)
throw new CHttpException(404,'The requested page does not exist.');
return $model;
}
示例2: beforeAction
public function beforeAction($action) {
if (parent::beforeAction($action)) {
$lang=Yii::app()->getRequest()->getPreferredLanguage();
if($lang=="ru_ru" || $lang=="ru")
Yii::app()->language="ru";
else
Yii::app()->language="en";
$board_array=Yii::app()->cache->get('boards');
if ($board_array===false) {
// show boards in top menu
$boards=Board::model()->findAll();
foreach ($boards as $board) {
$board_array[]=$action->getController()->boards[]=array('label'=> "/" . $board->slug . "/", 'url'=> array('/post/board', 'slug'=> $board->slug), 'linkOptions'=> array('title'=> $board->name));
}
Yii::app()->cache->set('boards', $board_array, 2592000); // 1 month
}
$action->getController()->boards=$board_array;
return true;
}
else
return false;
}
示例3: beforeSave
protected function beforeSave()
{
if(parent::beforeSave())
{
$board=Board::model()->findByPk($this->board);
$links=array();
preg_match_all("/>>\d+/",$this->content,$matches);
$matches=$matches[0];
foreach($matches as $match)
{
// delete >> symbols
$links[]=substr($match, 8);
}
$links=array_unique($links);
$posts=Post::model()->findAllByAttributes(array('board'=>$this->board,'vid'=>$links),array('order'=>'vid DESC'));
foreach($posts as $post)
{
$_id=$post->parent_id?$post->parent_id:$post->vid;
$url=array('post/thread','slug'=>$board->slug,'id'=>$_id);
if($post->parent_id)
$url=array('post/thread','slug'=>$board->slug,'id'=>$_id,'#'=>$post->vid);
$search = ">>".$post->vid;
$replace = CHtml::link(">>".$post->vid,$url,array('class'=>'ref'));
$this->content=str_replace($search,$replace,$this->content);
}
// flush cache
Yii::app()->cache->delete('board'.$board->slug);
if($this->isNewRecord)
{
$this->content=nl2br($this->content);
$this->created=time();
if($this->parent_id)
{
$post=Post::model()->find('board=:boardId AND vid=:id', array(':boardId'=>$this->board,':id'=>$this->parent_id));
$post->commentCount++;
if(strlen($this->filename)>0)
$post->commentWithImg++;
$post->updated=$this->created;
$post->save(false);
}
else
$this->updated=$this->created;
}
return true;
}
else
return false;
}