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

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

WBOY
WBOYOriginal
2016-06-13 08:43:53814browse

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