GithubHelp home page GithubHelp logo

hagfish's Introduction

HAGFISH - An Ugly PHP Framework

This is Hagfish. It is ugly.

Hagfish is not intended to be a heavyweight dolution that can handle everything, but rather a small framework that takes care of the common bits and pieces so you can concentrate on getting something built.

Hagfish provides simple routing, templating and database functionality. Everything else is up to you.

Your first Hagfish App

include 'hagfish/hagfish_core.php';

// Create a controller
$app = new HagfishController();

// Add an action
$app->addAction('default', function() { return "hello world"; });

// Dispatch
$app->dispatch();

That's it.

Adding actions

Actions are added inside the controller using the following:

$this->addAction('route', $handler);

For example, the following call "my_function" for a visit to http://myapp/hello

$this->addAction('hello', 'my_function');

Hagish supports the following actions:

// Class => method
$this->addAction('route', array('MyClass', 'someMethod'));

// HagfishAction => method
$this->addAction('route', array('MyHagfishAction', 'someMethod'));

// Object => method
$this->addAction('route', array(&$object, 'someMethod'));

// Function name
$this->addAction('route', 'my_function');

// Closure
$this->addAction('route', function() { });

Using a HagfishAction is the recommended method, as it gives access to the request and template functionality. Anything returned from a function will be sent to the browser.

Requests

Hagfish will optionally pass a HagfishRequest object to any action. Just define your actions as follows:

function myAction(HagfishRequest $request) {
	// Do stuff
}

Template control

First you must set up the template directory from your controller, usually in the constructor:

$this->setTemplatePath(dirname(__FILE__) . '/../templates/');

Then in your action, set the template you wish to use:

$this->setTemplateName('default');

Template files should follow the pattern whatever.template.php.

To add a variable to a template, do the following in your action:

$this->registerVariables(array(
	'variable'	=> $variable
));

$variable can then be used inside the template.

hagfish's People

Contributors

sodaware avatar

Watchers

 avatar James Cloos avatar

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.