|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* dummy "showcase" module |
|
4
|
|
|
*/ |
|
5
|
|
|
|
|
6
|
|
|
namespace Graviton\CoreBundle\Controller; |
|
7
|
|
|
|
|
8
|
|
|
use Graviton\RestBundle\Controller\RestController; |
|
9
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
10
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* This is just a dummy controller for demonstrating |
|
14
|
|
|
* the extension of generated bundles.. |
|
15
|
|
|
* |
|
16
|
|
|
* @author List of contributors <https://github.com/libgraviton/graviton/graphs/contributors> |
|
17
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GNU Public License |
|
18
|
|
|
* @link http://swisscom.ch |
|
19
|
|
|
*/ |
|
20
|
|
|
class ShowcaseExtensionController extends RestController |
|
21
|
|
|
{ |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* IMPORTANT NOTES IF YOU INHERIT FROM DYNAMICALLY GENERATED BUNDLE! |
|
25
|
|
|
* |
|
26
|
|
|
* Remember that if you want to change data and/or add fields; that those |
|
27
|
|
|
* fields must be present: |
|
28
|
|
|
* 1) in the originating Document |
|
29
|
|
|
* 2) in the serializer configuration |
|
30
|
|
|
* 3) maybe include validation rules in validation.xml |
|
31
|
|
|
* |
|
32
|
|
|
* it's not the right way to let something generate it and then completely change it's |
|
33
|
|
|
* structure. if you need something that you cannot generate so that you have to modify |
|
34
|
|
|
* *everything* when inheriting - don't generate it in the first place! ;-) |
|
35
|
|
|
* |
|
36
|
|
|
* the basic workflow is to define the entire structure in the json file, then here |
|
37
|
|
|
* (overriding) you *only* modify and alter data - don't add new properties. |
|
38
|
|
|
* |
|
39
|
|
|
* @param Request $request Current http request |
|
40
|
|
|
* |
|
41
|
|
|
* @throws \Exception |
|
42
|
|
|
* @throws \Graviton\ExceptionBundle\Exception\SerializationException |
|
43
|
|
|
* @return \Symfony\Component\HttpFoundation\Response $response Response with result or error |
|
44
|
|
|
*/ |
|
45
|
12 |
|
public function allAction(Request $request) |
|
46
|
|
|
{ |
|
47
|
12 |
|
$data = $this->getModel()->findAll($request); |
|
48
|
|
|
|
|
49
|
12 |
|
$response = $this->getResponse() |
|
50
|
12 |
|
->setStatusCode(Response::HTTP_OK) |
|
51
|
12 |
|
->setContent($this->serialize($data)); |
|
52
|
|
|
|
|
53
|
12 |
|
return $this->render( |
|
54
|
12 |
|
'GravitonCoreBundle:Main:index.json.twig', |
|
55
|
12 |
|
array('response' => $response->getContent()), |
|
56
|
|
|
$response |
|
57
|
6 |
|
); |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|