Symfony2 function usage instance analysis, symfony2 instance Analysis _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
Example analysis of Symfony2 function usage and symfony2 instance analysis. Symfony2 function usage instance analysis, symfony2 instance analysis this article describes the use of the Symfony2 function. For your reference, refer to: 1. call methods of other objects. Example analysis of Symfony2 function usage and symfony2 instance analysis

This example describes the usage of the Symfony2 function. We will share this with you for your reference. The details are as follows:

1. call methods of other objects.

Example:

$ Grobal_func = $ this-> container-> get ('global _ func '); // name of the 'global _ func' function $ lot_data = $ global_func-> getDataFromFile ($ parm1); // getDataFromFile function name

2. database preparation query

$conn = $this->em->getConnection();$sql_user="select * from lot_user where user_name=:param1 and user_id=:param2 limit 1";$params = array(    'param1' => $user,    'param2' => $uid);$ready = $conn->prepare($sql_user);$ready->execute($params);$result_user = $ready->fetchAll();

3. database rollback events

$em->getConnection()->beginTransaction();try{   $lotuser = new LotUser();   $lotuser->setId(0);   $lotuser->setUserId($user_id);   $lotuser->setUserName($user_name);   $lotuser->setPassword($password);   $lotuser->setUserTele($user_tele);   $lotuser->setEmail($email);   $lotuser->setRegDate($reg_date);   $lotuser->setIdNumber($id_number);   $lotuser->setRealUsername($real_username);$em->persist($lotuser);$em->flush();$em->getConnection()->commit();}catch(Exception $e){$e->getConnection()->rollback();}

I hope this article will help you design PHP programs based on the Symfony framework.

Articles you may be interested in:
  • Symfony2 joint query implementation method
  • Symfony2 create page instance details
  • Analysis on date usage in twig of symfony2.4
  • Session and cookie usage in Symfony2
  • Summary of how Symfony2 can obtain data from the database
  • Symfony2 framework learning Notes
  • Symfony2 study notes plugin format analysis
  • System route details for Symfony2 study notes
  • A detailed explanation of the controller usage of Symfony2 learning Notes
  • Template usage of Symfony2 learning Notes
  • How to install a third-party Bundles instance in Symfony2

The example in this article describes the usage of the Symfony2 function. For your reference, refer to: 1. call methods of other objects ....

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.