public function indexAction($args)
 {
     global $tpl;
     $page = new Page();
     $page->Page = isset($args['page']) ? (int) $args['page'] : 1;
     $page->PerPage = 12;
     $page->Condition = '';
     $page->Url = SITE_URL . 'index.php?job=admin_article&action=index';
     if ($args['cid']) {
         $page->Url .= '&cid=' . (int) $args['cid'];
         $tpl->assign('cid', $args['cid']);
     }
     $page->Url .= '&page=';
     //        if(isset($args['status']))
     //            $page->Condition .= 'status='.trim($args['status']);
     $result = Article::findAll($page, $args);
     $page->Count = $result['count'];
     //        if(!is_array($result['res']) || count($result['res'])<1)
     //            $articles = array();
     //mprint_r($result, '$result');
     //var_dump($result['res']);
     $post = $result['res'];
     if (is_array($post) && count($post) > 0) {
         foreach ($post as $key => $val) {
             $post[$key]->res = base64_encode(serialize($val));
         }
     }
     //var_dump($post);
     $categories = Category::findAll();
     $args['debug'] && mprint_r($categories, '$categories');
     $tpl->assign('categories', $categories);
     $tpl->assign('articles', $post);
     $tpl->assign('page_nav', $page->getPage());
     $tpl->display('admin/article_list.html');
 }
Example #2
0
	public function actionIndex()
	{
		$focusmap = Yii::app()->cache->get('aboutusfocusmap');
		if($focusmap == false){
			$focusmap = Img::model()->find(array(
					'select'=>'path',
					'condition'=>'typeid=5',
					'order'=>'createtime desc',
					'limit'=>'1',
			));
			Yii::app()->cache->set('aboutusfocusmap',$focusmap,3600*24*30);
		}
		
		$aModel = new Article;
		//查询5条最新的莱斯新闻
		$news = $aModel->findAll(array(
				'select'=>'id,title',
				'order'=>'sort desc,updatetime desc',
				'limit'=>10,
				));
		
		//根据ID 查询当前文章内容
		$nid = isset($_GET['id'])?intval($_GET['id']):0;
		
		if($nid!=0){
			$onenews = $aModel->find(array(
					'select'=>'operator,title,content,updatetime',
					'condition'=>"id=$nid",
					));
		}else{
			$this->render('404',array('msg'=>'你没有选择具体的新闻!'));
			exit;
		}
		
		$this->render('index',array(
				'news'=>$news,
				'focusmap'=>$focusmap,
				'onenews'=>$onenews,
				));
	}
Example #3
0
                    <tr>

                        <th>文章名称</th>
                        <th>作者</th>
                        <th>发布时间</th>
                        <th>修改时间</th>
                        <th>排序</th>
                        
                    </tr>
                </thead>
                <tbody>
                    <?php 
$model = new Article();
$de = new CDbCriteria();
$de->order = "sort DESC";
$all = $model->findAll($de);
foreach ($all as $key => $value) {
    $this->renderPartial("_view", array("data" => $value->attributes));
}
?>


                </tbody>
            </table>
        </div>
    </div>
</div>
<!-- END SAMPLE TABLE PORTLET-->
<link href="<?php 
echo Yii::app()->baseUrl;
?>
 public function actionEditblog($id)
 {
     $label = new Article();
     $labels = $label->findAll('userid=:uid', array(':uid' => Yii::app()->session['uid']));
     //$labesArray是对应于id,label键值的一维数组
     $labesArray[0] = '--请选择--';
     foreach ($labels as $l) {
         $labesArray[$l->id] = $l->label;
     }
     $blog = Blog::model();
     $blogInfo = $blog->findByPk($id);
     $blogInfotmp = $blogInfo;
     //存储到session[blogid] 防止imageUP后台处理时有添加一条记录到blog表中
     Yii::app()->session['blogid'] = $id;
     //七牛上传类
     Yii::import('application.vendors.*');
     require_once 'Qiniu/io.php';
     require_once 'Qiniu/rs.php';
     $bucket = Yii::app()->params['bucket'];
     $accessKey = Yii::app()->params['accessKey'];
     $secretKey = Yii::app()->params['secretKey'];
     if (isset($_POST['Blog'])) {
         $post = $_POST['Blog'];
         //$post['view'] = 0;
         $post['time'] = time();
         $post['userid'] = Yii::app()->session['uid'];
         $blogInfo->attributes = $post;
         if ($blogInfo->validate()) {
             /**
              * 处理图片
              * require_once 'UPimage/UPimage.php';		//图片缩略类
              * $resizeimage = new resizeimage("1.jpg", "320", "240", "1","2.jpg");
              * 1.缩略图
              * 2.文章图片 删除就行  添加记录由后台异步处理	//删除文章时处理
              */
             //echo CheckUploadFiles($_FILES['thumb']);die;
             //1
             //a 查出缩略图片并 b删除七牛上的图片	传递一个特殊的字符串
             $images = "";
             //拼接图片以@方式
             if (CheckUploadFiles($_FILES['thumb'])) {
                 //删除图片
                 $file = $_FILES['thumb'];
                 $type = ".jpg";
                 if (count($file['name']) != 0) {
                     foreach ($file['name'] as $key => $f) {
                         if (ImageTypeCheck($file['name'][$key], $file['size'][$key])) {
                             $newname = time() . rand(10000, 99999) . $type;
                             Qiniu_SetKeys($accessKey, $secretKey);
                             $putPolicy = new Qiniu_RS_PutPolicy($bucket);
                             $upToken = $putPolicy->Token(null);
                             list($ret, $err) = Qiniu_Put($upToken, $newname, file_get_contents($file['tmp_name'][$key]), null);
                             if ($err === null) {
                                 //成功
                                 $images .= "http://" . Yii::app()->params['bucket'] . "." . Yii::app()->params['domain'] . "/" . $newname . "@";
                             } else {
                                 //失败
                             }
                         }
                     }
                 }
                 //删除图片
                 $imgs = GetImageFileName($blogInfotmp->image);
                 Qiniu_SetKeys($accessKey, $secretKey);
                 $client = new Qiniu_MacHttpClient(null);
                 foreach ($imgs as $i) {
                     if (!isset($client)) {
                         $client = new Qiniu_MacHttpClient(null);
                     }
                     $err = Qiniu_RS_Delete($client, $bucket, $i);
                 }
             } else {
                 //没有上传图片 不做任何操作 保持原来的图片
                 $images = $blogInfo->image;
             }
             //$post['image'] = $images;
             $blogInfo->attributes = $post;
             //2
             //删除文章文字配图 和业务数据库中的记录
             //					Qiniu_SetKeys($accessKey, $secretKey);
             //					$client = new Qiniu_MacHttpClient(null);
             //					$imgageModel = Image::model();
             //					$textImage = $imgageModel->findAll('blogid=:bid',array('bid'=>$id));
             //					foreach ($textImage as $ti){
             //						if(!isset($client))
             //								$client = new Qiniu_MacHttpClient(null);
             //
             //							$err = Qiniu_RS_Delete($client, $bucket, $ti->image);
             //					}
             //					$imgageModel->deleteAll('blogid=:bid',array('bid'=>$id));
             $blogInfo->image = $images;
             $blogInfo->content = $_POST['content'];
             if ($blogInfo->save()) {
                 /**
                  * 注销blogid	必须的
                  */
                 Yii::app()->session['blogid'] = null;
                 Yii::app()->user->setFlash('sendblogsuccess', '修改文章成功 :)');
                 $this->redirect(array('articles'));
             }
         }
     }
     $data = array('labels' => $labesArray, 'blogModel' => $blogInfo);
     $this->render('editblog', $data);
 }