Skip to content

fizzka/phalcon-json-view

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

phalcon-json-view

Little stuff to make json responses in phalcon

Installation

clone repo or composer require fizzka/phalcon-json-view

Usage

Step 1

Customize your phalcon events manager:

use Fizz\Phalcon\JsonView\JsonView;
use Phalcon\Mvc\Dispatcher;

$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

Disable view:

use Phalcon\Mvc\View;

$di->set('view', function () {
    $view = new View();
    $view->disable();
    return $view;
}, true);

Step 3

Extend abstract class Fizz\Phalcon\JsonView\Controller;

use Fizz\Phalcon\JsonView\Controller;

class ExampleController extends Controller
{
	public function indexAction()
	{
		return ['foo' => 'baz'];
	}
}

Code example

Full-working example @see example.php

License

MIT

About

Little stuff to make json responses in phalcon

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages