-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample.php
More file actions
47 lines (34 loc) · 922 Bytes
/
Copy pathexample.php
File metadata and controls
47 lines (34 loc) · 922 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
use Fizz\Phalcon\JsonView\JsonView;
use Fizz\Phalcon\JsonView\Controller;
use Phalcon\Mvc\Dispatcher;
use Phalcon\Mvc\View;
use Phalcon\DI\FactoryDefault as DI;
use Phalcon\Mvc\Application as PhalconApp;
include 'vendor/autoload.php';
$di = new DI();
# Step 1
$di->set('dispatcher', function () use ($di) {
$eventsManager = $di->getShared('eventsManager');
$json = new JsonView();
$eventsManager->attach('dispatch:afterDispatchLoop', $json);
$dispatcher = new Dispatcher();
$dispatcher->setEventsManager($eventsManager);
return $dispatcher;
}, true);
# Step 2
$di->set('view', function () {
$view = new View();
$view->disable();
return $view;
}, true);
# Step 3
class ExampleController extends Controller
{
public function indexAction()
{
return ['foo' => 'baz'];
}
}
$app = new PhalconApp($di);
echo $app->handle('/example/index')->getContent();