Heim  >  Artikel  >  Backend-Entwicklung  >  openPNE常用方法分享_php技巧

openPNE常用方法分享_php技巧

WBOY
WBOYOriginal
2016-05-17 09:14:20962Durchsuche
复制代码 代码如下:

'asdfgasgsad'));?>这句话意思是包含'_sidemenu.php'并往其页面传一系列参数,'_sidemenu.php'页即可直接使用$form变量中的值
op_include_box('vote_question_create_box','asdfasdf',array('title'=>'创建问题','moreInfo'=>array('创建问题',link_to('创建问题2','@my_index'))));
?>
op_include_box('vote_question_create_box',get_slot('pager'),array('title'=>'创建问题','moreInfo'=>array('创建问题',link_to('创建问题2','@my_index'))));
?>
'vote_question_create_box'只是一个标记,'asdfasdf'或 get_slot('pager')则是要输出到页面上标题下的信息(这个方法里要包含slot只能用get_slot()不能用include_slot(),
而在页面中要包含slot则必须使用include_slot())
第三个数组参数中的键值名称title是固定的,是该段'vote_question_create_box'显示的标题,后面的'moreInfo'键名也是固定键值对应的数组则是罗列显示的内容列表

设定一个slot段落


包含指定的slot段落,设定的slot段落必须通过包含才能在页面上显示

op_include_form('vote_question_from',$form,array('title'=>'编辑问题','url'=>url_for('@vote_update?id='.$form->getObject()->getId()),));
?>包含一个表单对象,'vote_question_from'为标识名,$form为对应动作传来的表单对象,第三个数组参数title键值也url键值是固定的,分别对应显示的标题名和表单提交路径
对应动作内容为
public function executeEdit(sfWebRequest $request){
$object = $this->getRoute()->getObject();
//如果不是作者屏幕上显示404
$this->forward404Unless($this->getUser()->getMemberId() == $object->getMemberId());//$object->getMemberId()为传递过来的id值对应的那条记录的member_id字段值
$this->form = new VoteQuestionForm($object);
//访问此动作路径http://localhost/openpne/web/vote/edit/1
}
?>

用于分页时前后翻页的超链接
$pager来自动作里的 $this->pager = Doctrine::getTable('VoteQuestion')->getListPager($request->getParameter('page'));
PluginVoteQuestionTable类getListPager()方法里的内容↓
class PluginVoteQuestionTable extends Doctrine_Table
{
public function getListPager($page = 1,$size = 20)
{
$query = $this->createQuery()->orderBy('updated_at DESC');
$pager = new sfDoctrinePager('VoteQuestion',$size);//创建一个某表的分页对象,并传一个每页显示多少记录值
$pager->setQuery($query);//传一个查询语句对象
$pager->setPage($page);//设返回显示的页数
$pager->init();
return $pager;
}
}
?>
对应前台页面对分页结果集的沥遍
getResults() as $item): //利用openPNE分页机制获取指定分页结果集并沥遍每一条记录?>

getUpdatedAt(),'f') //'f'代表一种显示格式?>

getTitle(),count($item->getVoteAnswers())),'@vote_show?id='.$item->getId()) ?>




getId()) ?>相当于sdsfg
表名是驼峰模式在数据库里以下划线表示,字段名也是如此

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

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

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')
),
);
}
}
?>
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn