A fairly simple PHP framework using phpActiveRecord for the models and Smarty for the views
PHP
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
app
config
lib
public
vendor/framework
.gitignore
.htaccess
README.textile

README.textile

ARRGH.framework

ARRGH.framework is a dead simple php MVC framework, that I built to get my hands dirty with some PHP. It currently has database support with phpActiveRecord, and template support
with Smarty. It’s mainly some routing functions and a dispatcher that calls the appropriate controller and action by convention rather than configuration. It should be rather easy to setup with other ORMs or templating engines.

It’ll receive updates as long as I feel the urge to continue learning php. If you’re like, “WTF? Why would he…” the answer: php n00b. I usually program with Ruby ;) I’m going to try and setup the wiki as a tutorial.

Both Smarty and phpActiveRecord are located in the views directory.

Status

Pre-Alpha: Currently I am finishing up a rewrite of the routing system. It is nearly complete, and should route both static and non-nested resources. Nested resource support is coming, I’m just working on parsing it efficiently.

Default Setup

REQUIRES: PHP 5.3

I would recommend just checking out the repo, and starting there! The main directory for this repo acts as a functional example, framework core files are located in:

Arrgh.framework files located in: /vendor/framework

.htaccess

.htaccess in the root directory forwards to the public folder.
.htaccess in the public folder tells the application.php file to process the request UNLESS it matches a folder name.

Site Configuration (routes, database, paths)

config/

Database

  • If you want to change the file structure, you’ll need to modify: config/config.php
  • Database settings are also located in: config/config.php
  • I have included a demo routes file, in config/routes.php
  • All images, stylesheets, scripts, etc should be placed within the public folder.
  • NO HTML OR PHP FILES should go in the ‘public’ folder except application.php

Framework Routing

Routing files are located in:

/vendor/core/routing/
routing.php: this creates a RouteMap from the site routes.php file and matches the incoming url to a route
routemap.php: creates route objects using the site routes.php file
route.php: the route object
url.php: an object for the incoming URL
resource.php: an object for managing resource routes
nestedresource.php: same as resource, but for nested resources

Dispatcher

The dispatcher is simple, and takes a route object passed to it by the Routing class, then creates a new controller object based on the information in the route.

/vendor/core/dispatcher.php

Controllers

NAMING CONVENTION
* Filename: pluralized_controller.php (e.g. posts_controller.php, users_controller.php)
*
Controller classnames: CamelCaseEachWord. Class UsersController {}; Class UserSessionsController {};
** Controllers should extend the application controller
* Put site-wide controller logic in application_controller.php
* To load a page w/ the default controller, layout, and action: $this→view→render();
* Example controller located at: app/controllers/posts_controller.php

Models

  • Models should be singular (e.g. user.php, post.php)
  • Model classes need to extend phpActiveRecord
  • See phpActiveRecord doc for more info
  • Tip: passing the phpActiveRecord Object to Smarty is a pain, this is how I do it (from the controller).
$u = User::find(13);
$u = $u->to_json(array('except' => 'password'));
$u = json_decode($u);
$this->view->set('user', $u);
$this->view->render();
  • Example model located at: app/models/post.php

Views (Templates)

  • Templates work similarly to ruby on rails, with page templates in: app/views/layouts/ (where you put your HTML TAGS)
  • To pass variables from the controller to the template, you will need to assign them from
    their respective action with the following method: $this→view→set(‘var_name’, $var)
  • Template variables are Smarty variables, see Smarty doc to see how they work.
  • Templates need to use the .tpl extension (Smarty)
  • Logic should not be performed in the template, it should be performed in the controller.

Thanks & Notes

A few killer resources that helped me:

Big Thanks for this one
Write your own PHP MVC Framework (Part 1)
http://anantgarg.com/2009/03/13/write-your-own-php-mvc-framework-part-1/

PHP Template Engine
http://www.smarty.net/

phpActiveRecord — (currently down/dead? As such probably not the best ORM for this, but maybe I’ll fork it… Use GoogleCache or archive.org to find Docs)
http://www.phpactiverecord.org/

4 awesome PHP functions you must use every time
http://www.codeforest.net/4-awesome-php-functions-you-must-use-every-time

License

phpActiveRecord, Smarty, and jQuery have their own respective licenses and owners, and are subject to them. The code specifically for this framework, not including modifications to Smarty or phpActiveRecord or jQuery, is licensed under the MIT License included below.

Copyright © 2011 Servando Salazar

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.