Since this is a very new framework an introduction is in order.
First, Download the framework, we host it on Google Code and you can download it via Subversion.
Second, Put it on a server that supports PHP and MySQL. It does not have to be in a web viewable directory but currently it is recommended to be in /public_html/ root.
Setup the defines. There are a few defines that are nessisary to run PHP Simpl these must be declaired before the include of the class.
define('FS_SIMPL', '/public_html/simpl/');
define('DB_USER','user');
define('DB_HOST','localhost');
define('DB_PASS','pass');
define('DB_DEFAULT','my_blog');
define('DEBUG',false);
define('DEBUG_QUERY',false);
define('USE_CACHE',true);
define('CLEAR_CACHE',false);
The first one is manditory the rest are not, but it is a good idea to define them if you do not want to go into the main PHP Simpl config to change to debug mode or to clear the cache when you want to.
Next include the main class then load any helper classes you may need. This must be done before you include your own classes file.
include_once(FS_SIMPL . 'simpl.php');
$mySimpl->Load('Form');
$mySimpl->Load('Db');
$mySimpl->Load('DbTemplate');
$mySimpl->Load('Folder');
$mySimpl->Load('File');
$mySimpl->Load('Upload');
$mySimpl->Load('Image');
Now that you have PHPSIMPL up and running to write a simple class to mirror a mysql database table it is as simple as the example below.
class Post extends DbTemplate {
function Post($data=''){
$this->required = array('title','body');
$this->table = 'blog_post';
$labels = array('is_published'=>'Published:','user_id'=>'Author:','category_id'=>'Category:');
$examples = array('category_id'=>'ex. PHP, MySQL, Cars, XML, PHPSIMPL');
$this->DbTemplate($data, $this->required, $labels, $examples, $this->table);
}
}
And you are done, this Post class now has full interaction with the database table. You can use the helper GetValue() and SetValue() functions to get and set field values and all the helper functions to interact. You can also write custom functions just like you always would if you were not using PHP Simpl. A full list of functions and their parameters will be published soon, if you cannot wait just simply look through the PHP Simpl source, everything is commented in JavaDoc format for ease of use.
No comments:
Post a Comment