Common openpne Methods

Source: Internet
Author: User
Tags php foreach
<? PHP include_partial ('sidemo', array ('form' => 'asdfgasgsad ');?> This statement contains '_ sidemenu. php' and transmits a series of parameters to its page. You can directly use the value in the $ form variable on the' _ sidemenu. php' page.



<? PHP
Op_shortde_box ('vote _ question_create_box ',' <strong> ASDFASDF </strong> ', array ('title' => 'create question ', 'moreinfo' => array ('create question ', link_to ('create question 2',' @ my_index '))));
?>
<? PHP
Op_include_box ('vote _ question_create_box ', get_slot ('pager'), array ('title' => 'creation question', 'moreinfo' => array ('creation question ', link_to ('create question 2', '@ my_index '))));
?>
'Vote _ question_create_box 'is only a tag,' <strong> ASDFASDF </strong> 'or get_slot ('pager ') it is the information to be output to the title of the page (this method must contain slot. Only get_slot () can be used, and include_slot () cannot be used (),
To include slot in the page, you must use include_slot ())
The title of the key value in the third array parameter is fixed and is the title displayed in the 'vote _ question_create_box 'section, the subsequent 'morinfo' key name is also the array corresponding to the fixed key value, which is the list of displayed content



<? PHP slot ('pager');?> Set a slot Section
<? PHP echo 'asdfasgsadfasdfaaaaaaaaaaaaaaaaaaaaaaaaaa'?>
<? PHP end_slot ()?>
<? PHP include_slot ('pager');?> Contains the specified slot section. The specified slot section must be included before it can be displayed on the page.




<? PHP
Op_shortde_form ('vote _ question_from ', $ form, array ('title' => 'edit question', 'url' => url_for ('@ vote_update? Id = '. $ form-> GetObject ()-> GETID ()),));
?> Contains a form object. 'vote _ question_from 'is the Identification name, $ form is the form object sent from the corresponding action, and the title key value of the third array parameter is also fixed, corresponding to the displayed title and form submission path
The corresponding action content is
<? PHP
Public Function executeedit (sfwebrequest $ request ){
$ Object = $ this-> getroute ()-> GetObject ();
// If the screen is not displayed by the author 404
$ This-> forward404unless ($ this-> getuser ()-> getmemberid () = $ object-> getmemberid (); // $ object-> getmemberid () the value of the member_id field of the record corresponding to the passed id value
$ This-> form = new votequestionform ($ object );
// Access this action path http: // localhost/openpne/web/vote/edit/1
}
?>



<? PHP op_include_pager_navigation ($ pager, '@ tasks_list? Page = % D');?> Used as a hyperlink for paging back and forth pages
$ Pager: gettable ('votequestion ')-> getlistpager ($ request-> getparameter ('page '));
Content in the getlistpager () method of the pluginvotequestiontable class
<? PHP
Class pluginvotequestiontable extends doctrine_table
{
Public Function getlistpager ($ page = 1, $ size = 20)
{
$ Query = $ this-> createquery ()-> orderby ('updated _ at desc ');
$ Pager = new sfdoctrinepager ('votequestion ', $ size); // create a paging object for a table and pass the number of record values displayed on each page
$ Pager-> setquery ($ query); // transmits a query statement object
$ Pager-> setpage ($ page); // set the number of pages returned
$ Pager-> Init ();
Return $ pager;
}
}
?>
Displays the PAGE result set on the frontend page.
<? PHP foreach ($ pager-> getresults () as $ item): // use the openpne paging mechanism to retrieve the specified paging result set and drain each record?>
<DL>
<DT> <? PHP echo op_format_date ($ item-> getupdatedat (), 'F') // 'F' indicates a display format?> </DT> <! -- The op_format_date () method only replaces '-' in 2011-11-10 with the year, month, and day of Chinese characters. -->
<DD> <? PHP echo link_to (sprintf ("% s (% d)", $ item-> gettitle (), count ($ item-> getvoteanswers (), '@ vote_show? Id = '. $ item-> GETID ()?> </DD> <! -- $ Item-> gettitle () obtains the title value of the specified field in the record. -->
</Dl>
<? PHP endforeach;?>





<? PHP echo link_to ('sdsfg', '@ vote_show? Id = '. $ item-> GETID ()?> Equivalent to <a href = 'vote/show? Id =... '> sdsfg </a>




The table name is expressed by a line below the database in camper mode. The same is true for field names.



Linked
Even if you don't need a method, you can directly write the ==== Module name/action name ==== on the Web or the path after the Web is set in the route."




Action
$ This-> tasksobject = $ this-> getroute ()-> GetObject ();
$ This-> getroute ()-> GetObject (); // obtain the information object in the table corresponding to the passed ID parameter value through get + field name () obtain the field value, for example, $ tasksobject-GETID () on the page ();
As to how to determine which table is obtained, it is determined by setting the route through the routing class. The vote_question table is determined as follows:
Example
<? 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 ')
),

);
}
}
?>

<? PHP $ sf_user-> getmemberid ();?> // Obtain the ID of the current login. The $ sf_user object can be directly used on the page.

Action
<? PHP
$ This-> forward404unless ($ blood); // obtain a Boolean parameter. If it is true, the parameter is not executed. If it is false, the parameter is executed to jump to the 404 error page.
$ Request-> ismethod ('post'); // checks whether the currently passed method is post and returns true or false
$ This-> settemplate ('partial '); // redirects to the executepartial (sfwebrequest $ request) method. If the request is not redirected, the current value is not uploaded.
$ Request-> getparameter ('I'); // get the value passed by the specified key name, which can be obtained through post or get
?>
The symfony route also supports a module/Action/route address consisting of a key name/value, for example
Http: // localhost/openpne/web/My/index/I/6/O/90
You can get values 6 and 90 respectively through $ request-> getparameter ('I'); $ request-> getparameter ('O ');

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.