An example of Symfony2 function usages analysis _php

Source: Internet
Author: User

The examples in this article describe the use of Symfony2 functions. Share to everyone for your reference, specific as follows:

1. Methods to invoke other objects.

Cases:

$grobal _func= $this->container->get (' Global_func ');
The ' Global_func ' function contains the filename
$lot _data= $global _func->getdatafromfile ($parm 1);
Getdatafromfile Name of the letter

2. Preliminary query of database

$conn = $this->em->getconnection ();
$sql _user= "SELECT * from Lot_user where user_name=:p aram1 and user_id=:p aram2 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 with the PHP program design based on Symfony framework.

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.