Tico PHP MVC Framework: Framework to implement MVC applications in PHP

Recommend this page to a friend!
  Info   View files Example   View files View files (14)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2020-10-08 (1 month ago) RSS 2.0 feedNot yet rated by the usersTotal: 58 This week: 4All time: 9,835 This week: 49Up
Version License PHP version Categories
tico 1.0.0Artistic License5HTTP, PHP 5, Libraries, Design Patterns
Description Author

This package is a framework to implement MVC applications in PHP.

It provides an application class that has a fluent interface with functions to:

- Define model objects
- Define view objects
- Route HTTP requests that match certain URL patterns to handler functions
- Middleware functions to process details of the current HTTP request like user authentication, user sessions, etc..

The framework can handle all requests from a single application script.

Picture of Nikos M.
Name: Nikos M. is available for providing paid consulting. Contact Nikos M. .
Classes: 13 packages by
Country: Greece Greece
Age: 44
All time rank: 108610 in Greece Greece
Week rank: 13 Up1 in Greece Greece Up
Innovation award
Innovation award
Nominee: 5x

 

Details

tico

Tiny, super-simple but versatile quasi-MVC web framework for PHP (v.1.6.2)

Uses:

  1. Importer class & asset dependency loader
  2. Dromeo versatile pattern router
  3. InTpl simple php templates w/ inheritance
  4. `HttpFoundation` adapted from Symfony's HttpFoundation component

demo (see /demo/index.php)

define('ROOT', dirname(__FILE__));
include(ROOT.'/../tico/Tico.php');

class MyModel
{
    public function getMsg()
    {
        return "Hello";
    }
}

tico('http://localhost:8000', ROOT)
    ->option('views', tico()->path('/views'))
    ->set('model', new MyModel()) // simple dependency injection container
    ->middleware(function( $next ) {

        // eg check if user is authenticated,
        // for example check user cookie and set user var appropriately
        tico()->set('user', tico()->request()->cookies->get('user', 'guest'));
        // start session example (eg native php session)
        $session = new HttpSession(/array(..)/);
        tico()->request()->setSession($session);
        $session->start();
        if ( !$session->has('count') ) $session->set('count', 0);
        $next();

    })
    ->middleware(function( $next ) {

        // if this condition is met, abort current request, eg user is not authenticated
        if ( ('guest'==tico()->get('user')) && ('/hello/foo'==tico()->requestPath()) )
            //tico()->redirect(tico()->uri('/hello/bar'), 302);
            tico()->output(
                array('title' => 'Hello!', 'msg' => 'guest'),
                'hello.tpl.php'
            );
        // else pass along
        else
            $next();

    })
    ->on('*', '/', function( ) {

        tico()->output(
            array('title' => 'Demo Index'),
            'index.tpl.php'
        );

    })
    ->on(array('get', 'post'), '/hello/{:msg}', function( $params ) {

        $session = tico()->request()->getSession();
        $session->set('count', $session->get('count')+1);
        tico()->output(
            array(
                'title' => 'Hello!',
                'msg' => $params['msg'],
                'count'=> $session->get('count')
            ),
            'hello.tpl.php'
        );

    })
    ->on('*', '/json/api', function( ) {

        tico()->output(array(
            'param1' => '123',
            'param2' => '456',
            'param3' => '789'
        ), 'json');

    })
    ->on('*', '/download', function( ) {

        tico()->output(
            tico()->path('/file.txt'),
            'file'
        );

    })
    ->on('*', '/redirect', function( ) {

        tico()->redirect(tico()->uri('/'), 302);

    })
    ->on(false, function( ) {

        tico()->output(
            array(),
            '404.tpl.php',
            array('StatusCode' => 404)
        );

    })
    ->middleware(function( $next ) {

        // post process, eg create cache files from response
        if ( (200 == tico()->response()->getStatusCode()) && 'text/html'==tico()->response()->headers->get('Content-Type') && !tico()->response()->getFile() && !tico()->response()->getCallback() )
        {
            tico()->response()->setContent(tico()->response()->getContent().'<!-- post processed -->');
        }

    }, 'after')
    ->serve()
;
  Files folder image Files  
File Role Description
Files folder imagedemo (3 files, 1 directory)
Files folder imagetico (5 files)
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  demo  
File Role Description
Files folder imageviews (4 files, 1 directory)
  Accessible without login Plain text file file.txt Data Auxiliary data
  Accessible without login Plain text file index.php Example Example script
  Accessible without login Plain text file server.php Aux. Auxiliary script

  Files folder image Files  /  demo  /  views  
File Role Description
Files folder imagelayout (1 file)
  Accessible without login Plain text file 404.tpl.php Example Example script
  Accessible without login Plain text file content.tpl.php Example Example script
  Accessible without login Plain text file hello.tpl.php Example Example script
  Accessible without login Plain text file index.tpl.php Example Example script

  Files folder image Files  /  demo  /  views  /  layout  
File Role Description
  Accessible without login Plain text file base.tpl.php Example Example script

  Files folder image Files  /  tico  
File Role Description
  Plain text file Dromeo.php Class Class source
  Plain text file HttpFoundation.php Class Class source
  Plain text file Importer.php Class Class source
  Plain text file InTpl.php Class Class source
  Plain text file Tico.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:58
This week:4
All time:9,835
This week:49Up

For more information send a message to info at phpclasses dot org.