Home Backend Development PHP Tutorial openPNE常用方法分享_PHP

openPNE常用方法分享_PHP

Jun 01, 2016 pm 12:13 PM

复制代码 代码如下:
'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')
),
);
}
}
?>
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

11 Best PHP URL Shortener Scripts (Free and Premium) 11 Best PHP URL Shortener Scripts (Free and Premium) Mar 03, 2025 am 10:49 AM

11 Best PHP URL Shortener Scripts (Free and Premium)

Working with Flash Session Data in Laravel Working with Flash Session Data in Laravel Mar 12, 2025 pm 05:08 PM

Working with Flash Session Data in Laravel

Build a React App With a Laravel Back End: Part 2, React Build a React App With a Laravel Back End: Part 2, React Mar 04, 2025 am 09:33 AM

Build a React App With a Laravel Back End: Part 2, React

Simplified HTTP Response Mocking in Laravel Tests Simplified HTTP Response Mocking in Laravel Tests Mar 12, 2025 pm 05:09 PM

Simplified HTTP Response Mocking in Laravel Tests

cURL in PHP: How to Use the PHP cURL Extension in REST APIs cURL in PHP: How to Use the PHP cURL Extension in REST APIs Mar 14, 2025 am 11:42 AM

cURL in PHP: How to Use the PHP cURL Extension in REST APIs

12 Best PHP Chat Scripts on CodeCanyon 12 Best PHP Chat Scripts on CodeCanyon Mar 13, 2025 pm 12:08 PM

12 Best PHP Chat Scripts on CodeCanyon

Announcement of 2025 PHP Situation Survey Announcement of 2025 PHP Situation Survey Mar 03, 2025 pm 04:20 PM

Announcement of 2025 PHP Situation Survey

Notifications in Laravel Notifications in Laravel Mar 04, 2025 am 09:22 AM

Notifications in Laravel

See all articles