- 論壇徽章:
- 0
|
openPNE常用方法 - <?php include_partial('sidemenu',array('form'=>'asdfgasgsad'));?>這句話(huà)意思是包含'_sidemenu.php'并往其頁(yè)面?zhèn)饕幌盗袇?shù),'_sidemenu.php'頁(yè)即可直接使用$form變量中的值<?phpop_include_box('vote_question_create_box','<strong>asdfasdf</strong>',array('title'=>'創(chuàng)建問(wèn)題','moreInfo'=>array('創(chuàng)建問(wèn)題',link_to('創(chuàng)建問(wèn)題2','@my_index'))));?><?phpop_include_box('vote_question_create_box',get_slot('pager'),array('title'=>'創(chuàng)建問(wèn)題','moreInfo'=>array('創(chuàng)建問(wèn)題',link_to('創(chuàng)建問(wèn)題2','@my_index'))));?>'vote_question_create_box'只是一個(gè)標(biāo)記,'<strong>asdfasdf</strong>'或 get_slot('pager')則是要輸出到頁(yè)面上標(biāo)題下的信息(這個(gè)方法里要包含slot只能用get_slot()不能用include_slot(),而在頁(yè)面中要包含slot則必須使用include_slot())第三個(gè)數(shù)組參數(shù)中的鍵值名稱(chēng)title是固定的,是該段'vote_question_create_box'顯示的標(biāo)題,后面的'moreInfo'鍵名也是固定鍵值對(duì)應(yīng)的數(shù)組則是羅列顯示的內(nèi)容列表<?php slot('pager'); ?>設(shè)定一個(gè)slot段落<?php echo 'asdfasgsadfasdfaaaaaaaaaaaaaaaaaaaaaa' ?><?php end_slot() ?><?php include_slot('pager'); ?>包含指定的slot段落,設(shè)定的slot段落必須通過(guò)包含才能在頁(yè)面上顯示<?phpop_include_form('vote_question_from',$form,array('title'=>'編輯問(wèn)題','url'=>url_for('@vote_update?id='.$form->getObject()->getId()),));?>包含一個(gè)表單對(duì)象,'vote_question_from'為標(biāo)識(shí)名,$form為對(duì)應(yīng)動(dòng)作傳來(lái)的表單對(duì)象,第三個(gè)數(shù)組參數(shù)title鍵值也url鍵值是固定的,分別對(duì)應(yīng)顯示的標(biāo)題名和表單提交路徑對(duì)應(yīng)動(dòng)作內(nèi)容為<?phppublic function executeEdit(sfWebRequest $request){ $object = $this->getRoute()->getObject(); //如果不是作者屏幕上顯示404 $this->forward404Unless($this->getUser()->getMemberId() == $object->getMemberId());//$object->getMemberId()為傳遞過(guò)來(lái)的id值對(duì)應(yīng)的那條記錄的member_id字段值 $this->form = new VoteQuestionForm($object); //訪(fǎng)問(wèn)此動(dòng)作路徑http://localhost/openpne/web/vote/edit/1}?><?php op_include_pager_navigation($pager, '@tasks_list?page=%d'); ?>用于分頁(yè)時(shí)前后翻頁(yè)的超鏈接$pager來(lái)自動(dòng)作里的 $this->pager = Doctrine::getTable('VoteQuestion')->getListPager($request->getParameter('page'));PluginVoteQuestionTable類(lèi)getListPager()方法里的內(nèi)容↓<?phpclass PluginVoteQuestionTable extends Doctrine_Table{ public function getListPager($page = 1,$size = 20) { $query = $this->createQuery()->orderBy('updated_at DESC'); $pager = new sfDoctrinePager('VoteQuestion',$size);//創(chuàng)建一個(gè)某表的分頁(yè)對(duì)象,并傳一個(gè)每頁(yè)顯示多少記錄值 $pager->setQuery($query);//傳一個(gè)查詢(xún)語(yǔ)句對(duì)象 $pager->setPage($page);//設(shè)返回顯示的頁(yè)數(shù) $pager->init(); return $pager; }}?>對(duì)應(yīng)前臺(tái)頁(yè)面對(duì)分頁(yè)結(jié)果集的瀝遍<?php foreach($pager->getResults() as $item): //利用openPNE分頁(yè)機(jī)制獲取指定分頁(yè)結(jié)果集并瀝遍每一條記錄?><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()) ?>相當(dāng)于<a href='vote/show?id=...'>sdsfg</a>表名是駝峰模式在數(shù)據(jù)庫(kù)里以下劃線(xiàn)表示,字段名也是如此鏈接的就算不用方法也可以直接在action="此可直接寫(xiě)web/后的====模塊名/動(dòng)作名====或路由中設(shè)定好的web后的路徑"動(dòng)作里的$this->tasksObject = $this->getRoute()->getObject();$this->getRoute()->getObject();//獲取傳過(guò)來(lái)的id參數(shù)值對(duì)應(yīng)的表中的那條信息對(duì)象可通過(guò)get+字段名()獲取字段值,如在頁(yè)面中$tasksObject-getId();至于如何確定獲取的是哪個(gè)表則是通過(guò)路由類(lèi)設(shè)置該動(dòng)作路由時(shí)確定的,如下例確定的是vote_question表例<?phpclass 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') ), ); }}?>
復(fù)制代碼 |
|