标题: 我想用zf做个分类程序,有没有好的方法啊?
wohugb
PHPEye Developer
Rank: 8Rank: 8



UID 216
精华 0
积分 0
帖子 20
翻译 0
原创 0
阅读权限 1
注册 2007-7-23
状态 离线
发表于 2007-8-6 01:15  资料  主页 短消息  加为好友  添加 wohugb 为MSN好友 通过MSN和 wohugb 交谈
我想用zf做个分类程序,有没有好的方法啊?

我的zf知识有限,谁有没有好的方法,来做一个分类程序,我看利用已有的zf程序无法实现,如果谢插件plugin,谁有没有做过啊?我不大会做这个啊!

顶部
Haohappy
超级版主
Rank: 8Rank: 8
PHPEye站长


UID 2
精华 11
积分 110
帖子 285
翻译 6
原创 1
阅读权限 150
注册 2007-5-2
状态 离线
发表于 2007-8-6 08:37  资料  短消息  加为好友  添加 haohappy 为MSN好友 通过MSN和 haohappy 交谈
分类网站? 没什么特别的啊。不需要靠写什么插件来实现,从头开发吧。





互助共享,共同成长。
顶部
wohugb
PHPEye Developer
Rank: 8Rank: 8



UID 216
精华 0
积分 0
帖子 20
翻译 0
原创 0
阅读权限 1
注册 2007-7-23
状态 离线
发表于 2007-8-7 21:40  资料  主页 短消息  加为好友  添加 wohugb 为MSN好友 通过MSN和 wohugb 交谈
恩,还有个问题 在視圖中調用一個自定義函數應該怎麽做?

顶部
伶俜
新手上路
Rank: 1



UID 274
精华 0
积分 0
帖子 2
翻译 0
原创 0
阅读权限 10
注册 2007-8-10
状态 离线
发表于 2007-8-10 23:17  资料  短消息  加为好友  添加 伶俜 为MSN好友 通过MSN和 伶俜 交谈
i do this, but i don't know if any way better?????

[B]une idée.[/B]

1. add

QUOTE:
$sql .= " SQL_CALC_FOUND_ROWS ";

in line 133 zend/db/select.php
or rewrite the method

[B]2. Model[/B]

PHP代码如下:
class Album extends Zend_Db_Table
{
    protected 
$_name 'album';
    
        
//get le total nombre de résultat
    
public function getNombre()
    {
        
$res $this->_db->fetchRow("SELECT FOUND_ROWS() as total_nombre;");
        return 
$res["total_nombre"];
    }
}



[B]3. Controler[/B]

PHP代码如下:
class IndexController extends Zend_Controller_Action
{
    public function 
indexAction()
    {
        
$Album = new Album();
        
$page =  (int)$this->_request->getParam('page'0);
        
$where = array();//à ajouter
        
$sortby 'title';//à modifier

        
$this->view->albums $Album->fetchAll($where,$sortby,NUM_PAR_PAGE,$page*NUM_PAR_PAGE)->toArray();

        
$pagination = new Custom_Pagination($Album->getCountQuery(),$this->_request);

        
$this->view->pagination $pagination->render();
    }
}



NUM_PAR_PAGE is a const

[B]4.View (smarty)[/B]

PHP代码如下:
<table>
    {
section name=album loop=$albums}
    <
tr bgcolor="#FFFFFF">
        <
td align="center">{$albums[album].title}</td>
        <
td align="center">{$albums[album].artist}</td>
    </
tr>
    {/
section}
</
table>
{
$pagination}


[B]5. class Custom_Pagination[/B]

PHP代码如下:
class Custom_Pagination
{
    private 
$total_page;
    private 
$total_nombre;
    private 
$page_courante;
    private 
$_request;

    function 
__construct($total_nombre,$request)
    {
        
$this->_request = clone $request;
        
$this->page_courante $this->_request->getParam("page");
        
$this->total_page ceil($total_nombre/NUM_PAR_PAGE);
        
$this->total_nombre $total_nombre;
    }
    
    function 
render()
    {
                
//à ajouter les pages précédentes, suivantes .......
        
$html '';
        if(
$this->total_page 1)
        {
            for(
$i=0;$i<$this->total_page;$i++)
            {
                if(
$i>0)$html.= "/";
                
$this->_request->setParam("page",$i);
                
$html.= '<a href="'.$this->rebuildUrl().'">'.($i+1).'</a>';
            }
        }
        return 
$html;
    }
    
    
// reconstruire l'URL /album/index/index/page/1,/album/index/index/page/2,...
    //à améliorer. j'ai essayé $this->_request->setParam("page", $num_page); mais $this->_request->getRequestUri ne chage pas, si autre méthod?
    
function rebuildUrl()
    {
        
$url $this->_request->getBaseUrl();
        
$params $this->_request->getParams();
        
$url .="/".$params["module"];
        
$url .="/".$params["controller"];
        
$url .="/".$params["action"];
        foreach ( 
$params as $key=>$value)
        {
            if(!
in_array($key,array("module","controller","action")))
            
$url.="/".$key."/".$value;
        }
        return 
$url;
    }
}




顶部
wohugb
PHPEye Developer
Rank: 8Rank: 8



UID 216
精华 0
积分 0
帖子 20
翻译 0
原创 0
阅读权限 1
注册 2007-7-23
状态 离线
发表于 2007-8-18 01:28  资料  主页 短消息  加为好友  添加 wohugb 为MSN好友 通过MSN和 wohugb 交谈
谢谢,收下!

顶部
 


PHPEye开源社区


当前时区 GMT+8, 现在时间是 2009-1-9 05:40

    Powered by Discuz! 5.5.0  © 2001-2007 Comsenz Inc.
Processed in 0.025116 second(s), 6 queries , Gzip enabled

清除 Cookies - 联系我们 - PHPEye开源社区 - Archiver