本文實例講述了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程序設計有所幫助。