_GET,_POST, _COOKIE的同名变量的处理

  1. $version = '3000';
  2. foreach(array('_POST', '_GET', '_COOKIE') as $__R) {
  3. /*
  4. $__R : $_POST
  5. $__R : $_GET
  6. $__R : $_COOKIE
  7. */
  8. if($$__R) {
  9. // $_POST
  10. foreach($$__R as $__k => $__v) {
  11. // if has $_POST[version] = 6;
  12. // $__k is version
  13. // $$__k is $version
  14. // var_dump($__v);
  15. //var_dump(isset($$__k));
  16. // 如果已经设定值并且传递过来的值和设定的值相同则unset掉这个值
  17. if(isset($$__k) && $$__k == $__v)
  18. // 我觉得这里应该是unset掉传递过来的值,从而保证系统内值的使用
  19. unset($$__k);
  20. }
  21. }
  22. }

Symfony 和 Laravel 读取数据的对比

仅仅对比下两个框架读取数据的复杂和易用程度

  1. // laravel
  2. $next = (clone $Question)->orderBy('sort')->where('sort', '>', $entity->sort)->first('id')->value('id');
  3. $prev = (clone $Question)->orderBy('sort', 'desc')->where('sort', '<', $entity->sort)->first('id')->value('id');
  4. // symfony Doctrine
  5. $qb = $repository->createQueryBuilder("A");
  6. createWhere($qb, [
  7. "gt" => ["sort" => $entity->getSort()],
  8. "eq" => ["test_id" => $entity->getTestId()],
  9. ]);
  10. $qb->setFirstResult(0)->setMaxResults(1);
  11. $qb->orderBy("A.sort", "ASC");
  12. $rst = $qb->getQuery()->execute();
  13. if (count($rst) == 1) {
  14. if (isset($rst[0])) {
  15. $next = $rst[0]->getId();
  16. }
  17. }
  18. $qb = $repository->createQueryBuilder("A");
  19. // createWhere($qb,["lt"=>["sort"=>$entity->getSort()]]);
  20. createWhere($qb, [
  21. "lt" => ["sort" => $entity->getSort()],
  22. "eq" => ["test_id" => $entity->getTestId()],
  23. ]);
  24. $qb->orderBy("A.sort", "DESC");
  25. $qb->setFirstResult(0)->setMaxResults(1);
  26. $rst = $qb->getQuery()->execute();
  27. if (count($rst) == 1) {
  28. if (isset($rst[0])) {
  29. $prev = $rst[0]->getId();
  30. }
  31. }