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.