Skip to content
Luke Strickland edited this page Sep 6, 2013 · 4 revisions

With Frame, controllers are directly related to what is being outputted. This means Frame comes bundled with several different controller types you can use by simply extending the controller.

Plain Controllers

Plain controllers are the "default" controllers, they simply do whatever they're told, they can output json, html, anything.

<?php
class ExampleController extends Frame\Controller\Plain {

    public function index() {
        echo "This is a plain controller";
    }

}

JSON Controllers

JSON controllers output ONLY JSON and all application and framework specific messages are converted to JSON. To output JSON in a JSON controller you simply return the data of any type (even JSON!).

<?php
class ExampleController extends Frame\Controller\JSON {

    public function index() {
        $array = ['this' => 'is', 'an' => ['example']];

        return $array;
    }

}

Markdown Controllers

Requires dflydev/markdown

Markdown controllers automatically parse and output rendered Markdown.

<?php
class ExampleController extends Frame\Controller\Markdown {

    public function index() {
        $markdown = "### Welcome to my Website";

        return $markdown;
    }

}

Resource Controllers

Resource controllers are controllers that are directly binded to Models, based on Laravel Resource Controllers. Resource controllers come pre-routed and pre-coded, so to setup a Resource controller you just have to extend and set public $model = "YourModel";. Your Resource Controller comes pre-loaded with index(), show($id), create(), edit($id), update($id) and delete($id)

<?php
class ExampleController extends Frame\Controller\Resource {

    public $model = 'User';

    // The bootstrap resource is included in the inherited class, you can overwrite or create new ones

}

View Controllers

Requires twig/twig or mustache/mustache

View controllers are super special since they also include View Composers, which allow you to use any templating engine. To change the default view composer edit the configuration or set $composer in the controller with the namespaced class.

<?php
class ExampleController extends Frame\Controller\View {

    public $composer = 'Frame\\\Controller\\\Composers\\\Twig';
    
    public function index() {
        $todos = Todo::all();
        
        return $this->make('todo/list', compact('todos'));
    }

}