2017 © Pedro Peláez
 

library moca

Database and Cache providers

image

moca/moca

Database and Cache providers

  • Friday, July 12, 2013
  • by nikis
  • Repository
  • 1 Watchers
  • 0 Stars
  • 14 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Moca

Easy code scaling for Silex framework., (*1)

Usage

<?php

use Moca\Application\Controller;

class Page extends Controller {

    public function index() {
        return $this->view('index');
    }

    public function about() {
        return $this->view('about');
    }

    public function contacts() {
        return $this->view("contacts");
    }

    public function post_contacts() {
        $form = $this->app['request']->get('contacts');
        return $this->app->json(array('message' => 'Success'));
    }
}

Next mount your controller, (*2)

<?php
$app->mount('/', new Page());

What you need to know

  • All public methods of controller are register as routes
  • Default method for every controller is index
  • Every protected, private or parent method will be skipped
  • Every loaded route automatically adds /
  • You can change the request method by add it at the beginning post_routename or head_routename
  • Each controller name are added automatically as namespace in Twig
  • render are used to display the Twig templates. By default tempalte file extension is .phtml, if you want to change you can set option $ app['twig.options']['extension'] = '.html
  • view is seeking template filename defined in the View folder Default Twig folder + current name of the Controller
  • Middlewares before, after, beforeRender and afterRender

Examples

/contacts will accept only post, (*3)

<?php

use Moca\Application\Controller;

class Page extends Controller {

    public function index() {
        return $this->view('index');
    }

    public function about() {}

    public function post_contacts() {}
}

Will load the template from the folder View/Page/index.phtml, (*4)

<?php

use Moca\Application\Controller;

class Page extends Controller {

    public function index() {
        return $this->view('index');
    }
}

Will load the template from the folder View/Block/index.phtml, (*5)

<?php

use Moca\Application\Controller;

class User extends Controller {

    public function index() {
        return $this->render('Block/index');
    }
}

Composer, (*6)

{
    "require": {
        "moca/moca": "dev-master"
    }
}

Project structure, (*7)

vendor/
web/
app/
    Controller/
        Page.php
        User.php
    View/
        Page/
            Index.phtml
        User/
            Index.phtml
        Layout/
            Default.phtml

The Versions

12/07 2013

dev-master

9999999-dev https://github.com/nikis/Moca

Database and Cache providers

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Nikolay Tsanov

database cache