openPNE常用方法分享

2019-04-08 20:19:32丽君

$pager->init();
return $pager;
}
}
?>
对应前台页面对分页结果集的沥遍
<?php foreach($pager->getResults() as $item): //利用openPNE分页机制获取指定分页结果集并沥遍每一条记录?>
<dl>
<dt><?php echo op_format_date($item->getUpdatedAt(),'f') //'f'代表一种显示格式?></dt><!--op_format_date()方法只是把2011-11-10各种中的‘-'换成汉字年月日-->
<dd><?php echo link_to(sprintf("%s(%d)",$item->getTitle(),count($item->getVoteAnswers())),'@vote_show?id='.$item->getId()) ?></dd><!--$item->getTitle()获取该条记录指定字段title值-->
</dl>
<?php endforeach; ?>

<?php echo link_to('sdsfg','@vote_show?id='.$item->getId()) ?>相当于<a href='vote/show?id=...'>sdsfg</a>
表名是驼峰模式在数据库里以下划线表示,字段名也是如此

链接的
就算不用方法也可以直接在action="此可直接写web/后的====模块名/动作名====或路由中设定好的web后的路径"

动作里的
$this->tasksObject = $this->getRoute()->getObject();
$this->getRoute()->getObject();//获取传过来的id参数值对应的表中的那条信息对象可通过get+字段名()获取字段值,如在页面中$tasksObject-getId();
至于如何确定获取的是哪个表则是通过路由类设置该动作路由时确定的,如下例确定的是vote_question表

<?php
class opVotePluginFrontendRouteCollection extends sfRouteCollection
{
public function __construct(array $options)
{
parent::__construct($options);
$this->routes = array(
'vote_edit' => new sfDoctrineRoute(
'/vote/edit/:id',
array('module' => 'vote', 'action' => 'edit'),
array('id' => 'd+', 'sf_method' => array('get')),
array('model' => 'VoteQuestion', 'type' => 'object')
),
);
}
}
?>
相关文章 大家在看