0

This is my controller,

/**
 * @Route("/products")
 * @Template()
 */
public function productsAction() {
    if (isset($_GET)) {
            echo 'Category set';
            exit();
    }else{
            echo 'Category not set';
            exit();
    }
}

And this is the output I get,

Category set

http://localhost:8000/products by add this URL. It would be great help someone can look into it.

vimuth
  • 5,064
  • 33
  • 79
  • 116
  • 2
    `$_GET` = `array()` != `unset`. Even when you don't have any keys, it's still an empty array. – FirstOne Dec 24 '15 at 02:40
  • 3
    Possible duplicate of [How to check if $\_GET is empty?](http://stackoverflow.com/questions/3408616/how-to-check-if-get-is-empty) – FirstOne Dec 24 '15 at 02:42

2 Answers2

5

You shouldn't be trying to directly access the super-global $_GET if you are using the symfony framework for routing and the like.

If you are trying to do something when a category is present, instead, pass the category as a dynamic variable to the route as the 2nd argument. The first will be the function. Then $category will be available to you in the function.

/**
* @Route("/products/{category}")
* @Template()
*/
public function productsAction($category) {
    //$category is set so do something
    echo 'Category '. $category .' is set.';
}
Ohgodwhy
  • 49,779
  • 11
  • 80
  • 110
2

To add to @Ohgodwhy also do not use exit inside symfony.

Oras
  • 1,036
  • 1
  • 12
  • 18