Home > Backend Development > PHP Tutorial > Symfony2 function usage example analysis, symfony2 example analysis_PHP tutorial

Symfony2 function usage example analysis, symfony2 example analysis_PHP tutorial

WBOY
Release: 2016-07-12 08:56:31
Original
851 people have browsed it

Symfony2 function usage example analysis, symfony2 example analysis

This article describes the Symfony2 function usage with examples. Share it with everyone for your reference, the details are as follows:

1. Call methods of other objects.

Example:

$grobal_func=$this->container->get('global_func');
//'global_func'函数所在的文件名
$lot_data=$global_func->getDataFromFile($parm1);
//getDataFromFile函数名

Copy after login

2. Preparatory query of database

$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();

Copy after login

3. Database rollback event

$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();
}

Copy after login

I hope this article will be helpful to everyone’s PHP program design based on the Symfony framework.

Articles you may be interested in:

  • Symfony2 joint query implementation method
  • Detailed explanation of creating page instances in Symfony2
  • Analysis of date usage in twig of symfony2.4
  • Symfony2 session and cookie usage summary
  • Symfony2 method to obtain data from the database summary
  • Symfony2 framework study notes detailed explanation of form usage
  • Symfony2 learning Plug-in format analysis of notes
  • Detailed explanation of system routing of Symfony2 study notes
  • Detailed explanation of controller usage of Symfony2 study notes
  • Detailed explanation of template usage of Symfony2 study notes
  • Detailed explanation of installing third-party Bundle instances in Symfony2

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1111900.htmlTechArticleSymfony2 function usage example analysis, symfony2 example analysis This article describes the Symfony2 function usage with examples. Share it with everyone for your reference, the details are as follows: 1. Call methods of other objects. ...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template