<?php |
class ListAction extends Action{ |
public function index(){ |
import( 'Class.Category' ,APP_PATH); |
import( 'Class.Page' ,APP_PATH); |
|
$id = I( 'id' ); |
$cate = M( 'cate' )->order( 'sort' )->select(); |
$cids = Category::getChildrenID( $cate , $id ); |
$cids [] = $id ; |
|
$where = array ( 'del' => 0, 'cid' => array ( 'IN' , $cids )); |
$count = M( 'blog' )->where( $where )-> count (); |
$page = new Page( $count ,10); |
$limit = $page ->firstRow . ',' . $page ->listRows; |
$blog = D( 'BlogView' )->getData( $where , $limit ); |
|
$this ->blog = $blog ; |
$this ->page = $page ->show(); |
$this ->display(); |
} |
} |
?> |
//自己编写的model |
<?php |
Class BlogViewModel extends ViewModel { |
Protected $viewFields = array ( |
'blog' => array ( |
'id' , 'title' , 'time' , 'hits' , 'notes' , |
'_type' => 'LEFT' //关联方式 |
), |
'cate' => array ( |
'name' , '_on' => 'blog.cid=cate.id' //关联条件 |
) |
); |
Public function getData( $where , $limit ) { |
return $this ->where( $where )->limit( $limit )->order( 'time DESC' )->select(); |
} |
} |
?> |