例子:
Model文件:
$this->fetchAll(“is_jian=1″,”id DESC”,0,2)->toArray();//根据is_jian=1,按id倒序排列取前2条记录当第一个参数为null时,则直接按id倒序排列ASC为正序。
路由文件:
$video=new Video();//实例化数据库类
$this->view->get2Video =$video->get2Video();//取到2条首页推荐的数据
index.phtml文件:
<?php foreach ($this->get2Video as $video): ?>
<?=$video['id']; ?>
<?=$video['name']; ?>
<? endforeach; ?>
(全文…)
Posted on 12 一月 '10 by admin, under zend framework. No Comments.
经常性的看到如下的url:
http://www.junstudio.cn/id/4
或者更干脆
http://www.junstudio.cn/3
链接清爽,且搜索引擎友好.
ZF为我们提供了快速简单的实现方式,代码如下
//$front为前段控制器实例
$router = $front->getRouter();
//实现如http://www.junstudio.cn/id/4类型的url
$router->addRoute(‘test1′,
new Zend_Controller_Router_Route(‘id/:aid’,
array(
‘controller’=>’index’,
‘action’=>’view’
)
)
)
//实现如http://www.junstudio.cn/3类型的url
->addRoute(‘test2′,
new Zend_Controller_Router_Route(‘/:aid’,
array(
‘controller’=>’index’,
‘action’=>’view’
)
)
);
(全文…)
Posted on 30 四月 '09 by admin, under zend framework. 740 Comments.