Permalink
Browse files

Added new sample nginx vhost config. fixed readme.

  • Loading branch information...
1 parent 312f644 commit edee3e92155d7f8d9bc2740fac32ab3e57928433 @Xeoncross Xeoncross committed Dec 8, 2010
Showing with 47 additions and 10 deletions.
  1. 0 config.php → config.sample.php
  2. +24 −10 readme.markdown
  3. +23 −0 sample.nginx.conf
File renamed without changes.
View
@@ -1,37 +1,46 @@
## 1kb PHP MVC
-A working 1kb PHP framework with additional 1kb classes if needed.
+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.dsn'),c('db.user'),c('db.pass'));
+ $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);
- // OR
- $row = $db->row($sql,$params);
+ $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 User extends ORM
+ 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->select() and $user->count() methods to interact with database results. For example, you could approve inactive users like this:
+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 User;
- foreach($user->select(array('active'=>FALSE)) as $user)
+ $user = new Model_User;
+ foreach($user->get(array('active'=>FALSE)) as $user)
{
if($user->paid)
{
@@ -40,9 +49,14 @@ From there you can use the $user->select() and $user->count() methods to interac
}
}
+Or you can fetch a users posts:
+
+ $user = new Model_User;
+ $posts = $user->posts();
+
You can create users just as easily.
- $user = new User;
+ $user = new Model_User;
$user->name = 'John';
$user->email = 'john@example.com';
$user->save();
View
@@ -0,0 +1,23 @@
+# Basic server setup
+server {
+ listen 80;
+ server_name 1kbmvc.loc;
+ root /var/www/1kbmvc;
+ index index.html index.php;
+ try_files $uri @missing;
+
+ location @missing {
+ rewrite ^ /index.php$request_uri last;
+ }
+
+ # This will only run if the below location doesn't, so anything other than /index.php
+ location ~ \.php {
+ rewrite ^ /index.php$request_uri last;
+ }
+
+ # Pass index.php to PHP Fastcgi
+ location ^~ /index.php {
+ include fastcgi.conf;
+ fastcgi_pass 127.0.0.1:9000;
+ }
+}

0 comments on commit edee3e9

Please sign in to comment.