コード例 #1
0
 public function saveContent($model, $bodyModel)
 {
     $postDatas = Yii::$app->request->post();
     
     if ($model->load($postDatas) && $bodyModel->load($postDatas) && $model->validate() && $bodyModel->validate())
     {
         if ($model->summary === null || $model->summary === '')
         {
             if ($bodyModel->hasAttribute('body'))
             {
                 $content = strip_tags($bodyModel->body);
                 $pattern = '/\s/'; // 去除空白
                 $content = preg_replace($pattern, '', $content);
                 $model->summary = StringHelper::subStr($content, 250);
             }
         }
         if ($model->save())
         {
             $bodyModel->content_id = $model->id;
             $bodyModel->save();
             
             return $this->redirect([
                 'index'
             ]);
         }
     }
     return false;
 }
コード例 #2
0
echo $row['view_count'];
?>
°
            </span>
            <!-- .entry-meta -->
        </div>
        <!-- .entry-header -->
    </header>

    <div class="clearfix entry-content">
        <div class="article-summary">
        <?php 
if (!empty($row['thumb'])) {
    ?>
        <p><?php 
    echo StringHelper::subString($row['summary'], 90);
    ?>
&#8230;&#8230;</p>
        <?php 
} else {
    ?>
        <p><?php 
    echo $row['summary'];
    ?>
&#8230;&#8230;</p>
        <?php 
}
?>
            
        </div>
コード例 #3
0
ファイル: Content1.php プロジェクト: merlinxie/lulublog
 public function beforeSave($insert)
 {
     $uploadedFile = Common::uploadFile('Content[thumb]');
     if ($uploadedFile != null) {
         $this->thumb = $uploadedFile['url'] . $uploadedFile['new_name'];
     }
     if ($this->views == null) {
         $this->views = 0;
     }
     if ($this->comments == null) {
         $this->comments = 0;
     }
     if ($this->summary == null || empty($this->summary)) {
         $content = strip_tags($this->content);
         $pattern = '/\\s/';
         //去除空白
         $content = preg_replace($pattern, '', $content);
         $this->summary = StringHelper::subStr($content, 250);
     }
     return parent::beforeSave($insert);
 }