Giter Site home page Giter Site logo

stevencoulter / cricket Goto Github PK

View Code? Open in Web Editor NEW

This project forked from bhubauer/cricket

1.0 3.0 1.0 1.12 MB

This is the Cricket web application framework in PHP

License: GNU Lesser General Public License v2.1

PHP 5.17% CSS 0.33% JavaScript 1.30% HTML 93.20%

cricket's Introduction

Cricket

Cricket is a newly open sourced, yet very rich and mature PHP web application framework. Cricket has been used for more than 5 years on internal projects and we are happy to return some love to the community by sharing it with the world.

Even as you read this, we are in the middle of the open source migration. We are still creating all of the documentation and "getting started" instructions. Feel free to explore and stay tuned for more!

Cricket applications are built with Page and Component classes that are analogous to a desktop application's Window and View hierarchy. Cricket manages your state intuitively using just the instance variables in your Page and Component classes and allows your rendered HTML to directly link to (call) your component and page action methods.

Each page and component class can be bundled with its own resources (templates, images, js, css, etc.), and a component can render itself independently of the page and all other components. This independence allows pages and components to be truly sharable and reusable.

Features and benefits of Cricket:

  • Familiar GUI style component hierarchy where each component manages its own state and rendering.
  • Page and Component classes can bundle their own static resources for plug-and-play style reuse.
  • Template Inheritance
  • Direct linking of user actions to page and component methods

Please consult the WIKI for more details.

A simple example

Consider the following example of a simple page that contains a single component. This component displays a current "count" number and offers methods to increment or decrement the number. Click here for a live example of the following

The key things to make note of are:

  • The Page and Component classes are separate from the HTML layout (Controller and View of MVC)
  • The Page class adds the component as a child
  • The Component has state that is managed by cricket (instance variables)
  • The Component's template links directly to action methods in the Component class

First, lets look at the Page and Component classes

use cricket\core\Page;
use cricket\core\Component;


class CounterPanel extends Component {
    public $count = 0;
    
    public function render() {
        $this->renderTemplate("_counter_panel.php",array(
            'count' => $this->count,
        ));
    }
    
    public function action_increment() {
        $this->count++;
        $this->invalidate();
    }
    
    public function action_decrement() {
        $this->count--;
        $this->invalidate();
    }
}


class PageExample extends Page {

    public function init() {
        $this->addComponent(new CounterPanel('counter'));
    }

    public function render() {
        $this->renderTemplate("example.php");
    }
}

If you think of the above classes as the "Controllers" in a typical MVC paradigm, the following templates are the "views".

First, the page template

<?php
/* @var $cricket cricket\core\CricketContext */

use cricket\utils\Utils;
?>

<!DOCTYPE html>
<html>
    <head>
        <title>Example</title>
        ... some non-essentials remove for brevity ...
        <?= $cricket->head() ?>
    </head>
    <body>
        <div style="max-width:500px;">
            <h1>Basic Cricket Example</h1>
            <p>
                This example shows a simple Cricket page with one component.  
                The box below is rendered by a stand alone component object which is 
                able to interact with the user and update itself independently of the page.
            </p>
        </div>
        <?php $cricket->component("counter") ?>
    </body>
</html>

Next, lets look at the CounterPanel template:

<?php
/* @var $cricket cricket\core\CricketContext */
/* @var $count int */
?>

<div style="border: 4px dashed #cccccc; width:400px;padding:20px;">
    <div>
        Count = <?= $count ?>
    </div>
    <div style="margin-top:1em;">
        <input type="button" value = "-" onclick="<?= $cricket->onclick('decrement') ?>">
        &nbsp;
        <input type="button" value = "+" onclick="<?= $cricket->onclick('increment') ?>">
    </div>
</div>

cricket's People

Contributors

stevencoulter avatar bhubauer avatar scoulteragi avatar

Stargazers

 avatar

Watchers

James Cloos avatar Sami Cooper avatar  avatar

Forkers

scoulteragi

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.