README.md (2113B)
1 Bored is a PHP micro-framework. It provides a simple framework but you can 2 bring things together in order to refine your own ad-hoc framework; just don't 3 call the bored_run() function. The main documentation is the source code. 4 5 In a nutshell: 6 ``` 7 <?php 8 include('bored.php'); 9 10 route('GET', '/hello/!name', function($name) { 11 return "Hello ${name}"; 12 }); 13 14 bored_run(); 15 ?> 16 ``` 17 18 ### Concepts 19 Things bored will never have: 20 21 * An ORM 22 * A templating system 23 * Dependency injection 24 * Built-in database migration 25 * Unit testing 26 * More than 2000 SLOC. 27 28 Keep reading to learn about things bored do have. 29 30 ### Routing 31 It works like this: 32 33 ``` 34 route('GET', '/hello/?name', function($name = "Friend") { 35 return "Hello ${name}"; 36 }); 37 ``` 38 39 Argument prefixes are: !mandatory and ?optional. 40 41 ### Database 42 Database facilities are based on the mysqli PHP extension. It mainly consists 43 of a single function dbquery() which allows few but very convenient ways to 44 interact with the database. In order to enabled the database you have to define 45 four constants: 46 47 ``` 48 define('DBHOST', ''); 49 define('DBUSER', ''); 50 define('DBPASS', ''); 51 define('DBNAME', ''); 52 ``` 53 54 If one is missing, no DB connection gets opened and any call to dbquery() will 55 fails. Once all of the above has been defined a connection to the DB is made 56 available and it's possible to use dbquery(). Keep reading. 57 58 Fetch a single row: 59 ``` 60 $sql = "select id,username from users where id = 30"; 61 $user = dbquery($sql); 62 print_r($user); 63 ``` 64 65 This will results in the following: 66 67 ``` 68 Array 69 ( 70 [id] => 30 71 [username] => userfoo 72 ... 73 ) 74 ``` 75 76 Fetch multiple rows: 77 ``` 78 $sql = "select id,username from users"; 79 $users = dbquery($sql, -1); /* -1 means no limit */ 80 print_r($users); 81 ``` 82 83 This produces an output like this: 84 85 ``` 86 Array 87 ( 88 [0] => Array 89 ( 90 [id] => 248 91 [username] => userbar 92 ... 93 ) 94 95 [1] => Array 96 ( 97 [id] => 425 98 [username] => userbaz 99 ... 100 ) 101 ... 102 ) 103 ``` 104 105 ### Views 106 ... 107 108 ### Session 109 ... 110 111 ### Run-time cache 112 ... 113 114 ### Utils 115 116 #### Mails 117 ... 118 119 #### Output formatting 120 ...