search
Homephp教程php手册Symfony2函数用法实例分析,symfony2实例分析

Symfony2函数用法实例分析,symfony2实例分析

本文实例讲述了Symfony2函数用法。分享给大家供大家参考,具体如下:

1.调用其他对象的方法。

例:

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

2.数据库的预备查询

$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.数据库回滚事件

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

希望本文所述对大家基于Symfony框架的PHP程序设计有所帮助。

您可能感兴趣的文章:

  • Symfony2联合查询实现方法
  • Symfony2创建页面实例详解
  • symfony2.4的twig中date用法分析
  • Symfony2之session与cookie用法小结
  • Symfony2实现从数据库获取数据的方法小结
  • Symfony2框架学习笔记之表单用法详解
  • Symfony2学习笔记之插件格式分析
  • Symfony2学习笔记之系统路由详解
  • Symfony2学习笔记之控制器用法详解
  • Symfony2学习笔记之模板用法详解
  • Symfony2安装第三方Bundles实例详解
Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools