Behind the CRUD

Scaffolding is used by our CRUD controllers. Thanks to this additional layer of abstraction you can switch between different databases adapter without changing your controller actions or attached events. Scaffolding should be registered as DI service, therefore it can be used outside the CRUD.

In the following example we will use scaffolding with event manager to extend basic CRUD functionality:

namespace Foo\Controllers\Foo;

use Phalcon\Forms\Element\Text;
use Vegas\Mvc\Controller\Crud\Events;
use Vegas\Mvc\Controller\Crud;

class FooController extends Crud
    protected $formName = 'Foo\Forms\Foo';
    protected $modelName = 'Foo\Models\Foo';

    public function initialize()

        $this->dispatcher->getEventsManager()->attach(Events::AFTER_CREATE, function () {

        $this->dispatcher->getEventsManager()->attach(Events::AFTER_EDIT, function () {

    // ...

    private function changeFakeValue()
        $record = $this->scaffolding->getRecord();
        $record->fake = 'Fixed value';

    private function addExtraField()
        $form = $this->scaffolding->getForm($this->scaffolding->getRecord());

        $field = new Text('extra_field');
        $field->setLabel('Extra field');


    public function redirect(){
            'for' => 'foo/crud',
            'action' => 'index',