Skip to content
This repository has been archived by the owner on Feb 19, 2019. It is now read-only.

Latest commit

 

History

History
49 lines (36 loc) · 1.04 KB

controllers.rst

File metadata and controls

49 lines (36 loc) · 1.04 KB

Controllers

Controllers will be called after matching a URL.

The framework includes a base Controller class which can be extended.

The base controller has a property crispySystem which contains a copy of the Container class for Dependency Injection.

Controllers must return a string.

Example

<?php

namespace App\Controllers;

use StevenLiebregt\CrispySystem\Controllers\Controller;
use StevenLiebregt\CrispySystem\View\SmartyView;

class ProductsController extends Controller
{
    private $view;

    public __construct(SmartyView $view)
    {
        $this->view = $view;
    }

    public function index()
    {
        return $this->view
            ->template('index.tpl')
            ->display();
    }

    public function item($id)
    {
        return $this->view
            ->template('item.tpl')
            ->with([
                'id' => $id,
            ])
            ->display();
    }
}