symfony 学习 2 数据库操作 CRUD
来源:互联网 发布:绝地求生渣显卡优化 编辑:程序博客网 时间:2024/06/05 19:33
<?phpnamespace AppBundle\Controller;// use Symfony\Bundle\FrameworkBundle\Controller\Controller;use AppBundle\CommonController;use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;use Symfony\Component\HttpFoundation\Request;use Symfony\Component\HttpFoundation\RedirectResponse;use AppBundle\Entity\Roles;/** * @Route("/roles") */class RolesController extends CommonController{ /** * @Route("/index",name="roles_index") */ public function indexAction(Request $request) { // $repository = $this->getDoctrine() // ->getRepository('AppBundle:Roles'); // //查询所有产品 // $roles=$repository->findAll(); // return $this->render('AppBundle:Roles:index.html.twig', array( // // ... // 'roles'=>$roles // )); // $em = $this->getDoctrine()->getManager(); $qb = $em->getRepository('AppBundle:Roles')->createQueryBuilder('n'); $paginator = $this->get('knp_paginator'); $pagination = $paginator->paginate($qb, $request->query->getInt('page', 1),3); return $this->render('AppBundle:Roles:index.html.twig', [ 'pagination' => $pagination, ]); } /** * @Route("/edit") */ public function editAction() { return $this->render('AppBundle:Roles:edit.html.twig', array( // ... )); } /** * @Route("/update") */ public function updateAction() { return $this->render('AppBundle:Roles:update.html.twig', array( // ... )); } /** * @Route("/create") */ public function createAction() { return $this->render('AppBundle:Roles:store.html.twig', array( // ... )); } /** * @Route("/store") */ public function storeAction(Request $request) { $title = $request->request->get('name'); $roles = new Roles(); $roles->setName($title); $em = $this->getDoctrine()->getEntityManager(); $em->persist($roles); $em->flush(); return $this->redirect($this->generateUrl('roles_index'), 301); } /** * @Route("/delete") */ public function deleteAction() { return $this->render('AppBundle:Roles:delete.html.twig', array( // ... )); }}
0 0
- symfony 学习 2 数据库操作 CRUD
- 【ThinkPHP学习】数据库CRUD操作
- 数据库 CRUD操作
- JDBC操作数据库CRUD
- CRUD---数据库SQL操作
- 数据库CRUD操作
- mysql数据库CRUD操作
- 数据库 CRUD操作
- SpeedPHP框架学习-2.数据库CRUD操作和Smarty操作
- 不同版本Symfony对数据库操作区别
- MyBatis学习(2)-----------执行CRUD操作
- 数据库约束和CRUD操作
- MySQL数据库的CRUD操作
- 模型的数据库CRUD操作
- symfony 学习
- Symfony 学习
- 使用JDBC操作数据库(CRUD基本操作)
- MyBatis学习记录(2):单表的CRUD操作
- 登录验证码(验证码图片用jsp显示出来的)
- Java并发编程学习路线图
- android 利用系统控件实现下拉刷新。
- mysql 修改utf8mb4
- 让Redis在你的系统中发挥更大作用
- symfony 学习 2 数据库操作 CRUD
- 从源代码分析Universal-Image-Loader中的线程池
- CentOS JDK安装
- 浅析.tbd与.dylib
- 常用技术网站
- Java NIO概述
- Android将程序崩溃信息保存本地文件
- 京东无线服务端架构演进历程
- 更新android sdk出现 A folder failed to be renamed or moved