Openpne common methods to share _php skills

Source: Internet
Author: User
Copy Code code as follows:

<?php include_partial (' Sidemenu ', Array (' form ' => ' Asdfgasgsad '));? > The meaning is to include ' _sidemenu.php ' and pass a series of parameters to its page, the ' _sidemenu.php ' page can use the value of $form variable directly
<?php
Op_include_box (' Vote_question_create_box ', ' <strong>asdfasdf</strong> ', Array (' title ' => ' Create question ', ' MoreInfo ' =>array (' Create Problem ', link_to (' Create question 2 ', ' @my_index ')));
?>
<?php
Op_include_box (' Vote_question_create_box ', get_slot (' pager '), Array (' title ' => ' Create question ', ' moreinfo ' =>array ') (' Create problem ', link_to (' Create question 2 ', ' @my_index '));
?>
' Vote_question_create_box ' is just a mark, ' <strong>asdfasdf</strong> ' or get_slot (' pager ') is the information to be exported to the title on the page ( This method must contain slot only Get_slot () cannot be used Include_slot (),
To include slot in the page, you must use Include_slot ())
The name title of the key value in the third array parameter is fixed, is the caption displayed by the ' Vote_question_create_box ', and the following ' MoreInfo ' key name is the array of fixed key values, which is the list of contents to display

<?php slot (' pager ');?> set a slot paragraph
<?php echo ' asdfasgsadfasdfaaaaaaaaaaaaaaaaaaaaaa '?>
<?php End_slot ()?>
<?php include_slot (' pager ');?> contains the specified slot paragraph, the set slot paragraph must be included to display on the page

<?php
Op_include_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 identity name, $form for the corresponding action from the Form object, the third array parameter title key value is fixed, corresponding to the display of the title name and form submission path
The corresponding action content is
<?php
Public Function Executeedit (sfwebrequest $request) {
$object = $this->getroute ()->getobject ();
If not the author screen shows 404
$this->forward404unless ($this->getuser ()->getmemberid () = = $object->getmemberid ());//$object-> Getmemberid () The MEMBER_ID field value of the record that corresponds to the ID value passed over
$this->form = new Votequestionform ($object);
Access this motion path HTTP://LOCALHOST/OPENPNE/WEB/VOTE/EDIT/1
}
?>

<?php op_include_pager_navigation ($pager, ' @tasks_list? page=%d ');?> hyperlinks to and from pages when paging
$pager from the $this in action->pager = doctrine::gettable (' votequestion ')->getlistpager ($request->getparameter (' Page '));
Content ↓ in the Pluginvotequestiontable Class Getlistpager () method
<?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 Page object for a table, and pass a value of how many records each page displays
$pager->setquery ($query);//Pass a query statement object
$pager->setpage ($page);//Set number of pages to return display
$pager->init ();
return $pager;
}
}
?>
The corresponding front page to the paging result set of the drain
<?php foreach ($pager->getresults () as $item):///Use the OPENPNE paging mechanism to get the specified paging result set and to drain each record?>
<dl>
<dt><?php Echo op_format_date ($item->getupdatedat (), ' f ')//' F ' represents a display format?></dt><!--op_ Format_date () method is only the 2011-11-10 of the '-' change to Chinese characters month and day-->
<dd><?php Echo link_to (sprintf ("%s (%d)", $item->gettitle (), Count ($item->getvoteanswers ())), ' @vote_ Show?id= '. $item->getid ())?></dd><!--$item->gettitle () Get this record to specify the field title value-->
</dl>
<?php Endforeach;?>

<?php echo link_to (' SDSFG ', ' @vote_show? id= '. $item->getid ())?> is equivalent to <a href= ' vote/show?id= ... ' &GT;SDSFG </a>
The table name is the hump pattern, which is underlined in the database, and so is the field name

Linked to
Even if you do not use the method can be directly in the action= "This can directly write the web/after the module name/action name = = or route set in the path after the Web"

In action.
$this->tasksobject = $this->getroute ()->getobject ();
$this->getroute ()->getobject ();//Get the Information object in the table that corresponds to the ID parameter value can get the field value by get+ field name (), as in the page $tasksobject-getid ();
As for how to determine which table is being acquired is determined by the routing class when the action route is set, the following example determines the Vote_question table
Cases
<?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 ')
),
);
}
}
?>

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.