Coder Social home page Coder Social logo

jamesatracy / backbone.php Goto Github PK

View Code? Open in Web Editor NEW
1.0 4.0 0.0 1.5 MB

Backbone.php is a lightweight collection of scripts that provide structure or scaffolding for a php application or php powered website.

CSS 5.70% JavaScript 20.24% PHP 74.05%

backbone.php's Introduction

Backbone.php

Build Status

Backbone.php, much like its javascript namesake, is a small collection of PHP classes that provide structure or scaffolding for a PHP application or PHP powered website. It follows the Model-View-Controller (MVC) convention and includes classes for handling routes, database backed models, and HTML views. Applications or websites built using Backbone.php can be up and running very quickly because it removes the necessity of writing much boilerplate code.

NOTE: This project is pre-1.0 and the code may change in significant and backward incompatible ways between releases.

The framework is built with the following goals in mind:

  • Lightweight: The core of Backbone.php provides just the right amount of structure and flexibility without being overly complicated.

  • Modular: Backbone.php is highly modular and provides a simple mechanism for including other framework and application specific modules.

  • Best Practices: Backbone.php is designed with software engineering best practices in mind, including MVC, Object-Oriented programming, and unit testing.

At its most simplest form, a Backbone.php application is nothing more than a series of url routes (such as "/about/") that are mapped to either views ("views/about-page.php") or callback methods ("public function about($request)") or combinations of both.

You can define routes for any HTTP method:

// index is a global function
Router::get("/", "index");
Router::post("/", "index");
Router::put("/", "index");
Router::delete("/", "index");
Router::method("CUSTOM", "/", "index");

You can route requests directly to view files:

// routes to view file located at /views/about.php
Router::get("/about", "View@about");
// routes to view file located at /views/about/jobs.php
Router::get("/about/jobs/", "View@about/jobs");

You can route requests to controller methods:

// routes to AppController->index() located at /controllers/AppController.class.php
Router::get("/", "/controllers/AppController@index");

public function index($request)
{
	...
}

You can create routes with url arguments:

Router::get("/path/:name/:id/", "/controllers/AppController@doSomething");

public function doSomething($request, $name, $id)
{
	...
}

You can also define route aliases so that you can generate links with correct paths:

Router::get("/", "/controllers/MyController@index")->alias("home");
Router::getRouteFromAlias("home");
// returns "/"

You can even use getRouteFromAlias to generate paths with url arguments filled in:

Router::get("/jobs/:department/:id/", "/controllers/MyController@jobDesc")->alias("job-description");
Router::getRouteFromAlias("job-description", array("engineering", 24));
// returns "/jobs/engineering/24/"

That is essentially all that you need to get a Backbone.php application up and running. However, the framework also provides a number of classes for working specifically with data backed by a SQL database in the form of Models and Collections.

$dog = Dog::create({
	"name" => "Spot",
	"breed" => "Collie"
});
$id = $dog->id;

$dog = Dog::fetch(1); // with id = 1
$dog->name = "Spot";
$dog->save();

$dogs = Dog::fetch()->where("breed", "Collie")->limit(10)->exec();
while($dog->valid()) {
	$dog = $dog->next();
	...
}

Classes

The Backbone.php framework consists of the following 14 modules:

Backbone, Collection, DB, Events, Html, Model, Query, Response, Request, Router, Sanitize, Schema, Validate, and View

Dependencies

Requires PHP version 5.3+.

Documentation

For all of the documentation, please go to the documentation table of contents

See api documentation in /docs/api/index.html

Version History

Please see version history.

backbone.php's People

Contributors

jamesatracy avatar raymsmith avatar

Stargazers

Cristian avatar

Watchers

James Cloos avatar Ismail K avatar  avatar  avatar

backbone.php's Issues

Router: Support HTTP Methods

Add support for specifying HTTP methods (GET, POST, PUT, DELETE, etc.) as part of a route. For some backwards compat. by default routes will support all methods.

"/path/to/animal/:number/" => array(
"GET" => "getAnimal",
"UPDATE" => "updateAnimal"
);

Alternative syntax:

$this->get("/path/to/animal/:number/", "getAnimal");
$this->update("/path/to/animal/:number/", "updateAnimal");

$this->any("/path/to/whatever/", "doWhatever");

Finish MySQL unit tests.

The unit tests for MySQL currently only cover generating SELECT statements. Tests need to be written for generating INSERT, UPDATE, DELETE, and DESCRIBE statements.

View: Support caching of views

I would like to support the caching of fully rendered views on the disk. This would be off by default and require some configurations, like cache time.

It would also need to be able to intelligently update the cache when the view's code file changes. This may actually be difficult since views can extend others and call view fragments.

Schema cache

Schema doesn't properly save the field definitions when loading from its static internal cache.

Collection iterator

The Collection iterator's current() method assumes a relative path of "/models/" when loading a Model class before creating an instance. It should not assume any path, since there is no MODELPATH global constant. Instead, the user should provide the full relative path to the Model.

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.