Git Product home page Git Product logo

1kb-php-mvc-framework's Introduction

1kb PHP MVC

A working 1kb PHP framework with additional 1kb classes if needed. To get started, copy config.sample.php to config.php and edit as needed.

Connecting to a database is easy.

$db = new DB(c('db'));

All queries are prepared statements to prevent SQL injection.

$statement = $db->query($sql, $params);

You can also use the helper functions if you wish to request one or more results.

$rows = $db->fetch($sql, $params);		// All rows
$row = $db->row($sql,$params);			// Single row
$column = $db->column($sql,$params,3);	// Third column

To use the ORM create classes that map to database tables.

class Model_User extends ORM
{
	static $t = 'user';
	static $k = 'id';
	static $f = 'user_id';
	static $r = array(
		'posts' => 'Model_Post',		// Has many posts
		'roles' => 'Model_Role',		// Has many roles
		'profile' => 'Model_Profile',	// Has one profile
	);
	static $b = array('roles' => 'Model_Role');		// Belongs to roles
}

You also need to set the database connection the ORM will use.

ORM::$db = $db;
//OR
Model_User::$db = $db;

From there you can use the $user->get() and $user->count() methods to interact with database results. For example, you could approve inactive users like this:

$user = new Model_User;
foreach($user->get(array('active'=>FALSE)) as $user)
{
	if($user->paid)
	{
		$user->active = TRUE;
		$user->save();
	}
}

Or you can fetch a users posts:

$user = new Model_User;
$posts = $user->posts();

You can create users just as easily.

$user = new Model_User;
$user->name = 'John';
$user->email = '[email protected]';
$user->save();

Lots of other fun things can be done in only 1kb.
Read the code man, read the code.

David Pennington
Released under the MIT License

1kb-php-mvc-framework's People

Contributors

xeoncross avatar

Watchers

James Cloos avatar Aleksandar Bus Jovic 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.