Permalink
Browse files

Add statusCode configuration to View annotation

  • Loading branch information...
1 parent cbfa6b3 commit fb8751a4f583a4007f62024cddaf1b4520113f0e @Seldaek Seldaek committed Apr 5, 2012
Showing with 43 additions and 2 deletions.
  1. +21 −0 Controller/Annotations/View.php
  2. +7 −2 EventListener/ViewResponseListener.php
  3. +15 −0 Resources/doc/3-listener-support.md
@@ -24,6 +24,11 @@ class View extends Template
*/
protected $templateVar;
+ /**
+ * @var int
+ */
+ protected $statusCode;
+
/**
* Returns the annotation alias name.
*
@@ -54,4 +59,20 @@ public function getTemplateVar()
{
return $this->templateVar;
}
+
+ /**
+ * @param int $statusCode
+ */
+ public function setStatusCode($statusCode)
+ {
+ $this->statusCode = $statusCode;
+ }
+
+ /**
+ * @return int
+ */
+ public function getStatusCode()
+ {
+ return $this->statusCode;
+ }
}
@@ -80,8 +80,13 @@ public function onKernelView(GetResponseForControllerResultEvent $event)
$view = new View($view);
}
- if ($configuration && $configuration->getTemplateVar()) {
- $view->setTemplateVar($configuration->getTemplateVar());
+ if ($configuration) {
+ if ($configuration->getTemplateVar()) {
+ $view->setTemplateVar($configuration->getTemplateVar());
+ }
+ if ($configuration->getStatusCode()) {
+ $view->setStatusCode($configuration->getStatusCode());
+ }
}
if (null === $view->getFormat()) {
@@ -100,6 +100,21 @@ public function getUsersAction()
//...
}
```
+
+The status code of the view can also be configured:
+
+```php
+<?php
+
+/**
+ * @View(statusCode=204)
+ */
+public function deleteUserAction()
+{
+ //...
+}
+```
+
See the following example code for more details:
https://github.com/liip/LiipHelloBundle/blob/master/Controller/ExtraController.php

0 comments on commit fb8751a

Please sign in to comment.