A small PHP framework that implements MVC design pattern. This framework is created with the intent to give the author knowledge about php and at the same time be usable for the community.
composer create-project shinidev/sapling directory
You can edit the .envtemplate file to correspond to your database configuration, after editing it create a copy and name it .env. It is what Sapling reads for your database configurations. You should not include your .env file when uploading your repository to github.
In here you can enable Sapling's error reporting. Sapling's error reporting is on by default. DEVELOPMENT, when true displays error. STRICT, when true kills the application if there are errors. Note, that this is seperate from php error reporting, if you want to enable php error reporting go to your .env file and set DEVELOPMENT to "TRUE".
In here you can set your base url, default controller, default function and error page directory.
This is where you're gonna load your models and views.
$this->loadModel('modelFile', 'optionalname')
$this->ModelFile->function() or $this->OptionalName->function()
$this->loadView('viewFile', 'optionalData')
This is where you're going to communicate to your database. Model classes is recommended to extend the QueryBuilder class.
$this->table('tablename'); // sets the table to insert data to $this->insert(['columns'], ['datas']); // tells what columns and corresponding data // Insert only needs a table name
$this->table('tablename'); // sets the table to get data from $this->whereMany(['columns'], ['values']); // Sets the where clause based on the given columns and values // or $this->whereSpecific('column', value, '!='); // Appends and sets the specific column and its value one by one. // or $this->whereManual("WHERE column = ?", [values]); // Set the where clause manually. $this->join('left', 'tablename', 'on condition'); // Joins tables $this->order('column'); // Order by column $this->limit(100); // Limits result $this->select(['columns']); // Selects columns // Select only needs a table, all the others are optional
$this->table('tablename'); // sets the table to get data from $this->whereMany(['columns'], ['values']); // Sets the where clause based on the given columns and values // or $this->whereSpecific('column', value, '!='); // Appends and sets the specific column and its value one by one. // or $this->whereManual("WHERE column = ?", [values]); // Set the where clause manually. // It is necessary to have always setted the where clause or else Sapling will display error $this->update(['columns'], [values]);
$this->table('tablename'); // sets the table to get data from $this->whereMany(['columns'], ['values']); // Sets the where clause based on the given columns and values // or $this->whereSpecific('column', value, '!='); // Appends and sets the specific column and its value one by one. // or $this->whereManual("WHERE column = ?", [values]); // Set the where clause manually. // It is necessary to have always setted the where clause or else Sapling will display error $this->delete(); // Deletes rows based on the where clause that is setted.
$this->getLastQuery(); // returns a string
Url::baseUrl();
Url::redirect(url);
http://localhost/Sapling/controller/method/param1/param2/param3 // The url above passes 3 parameters to a controller function. public function test(param1, param2, param3); // Your controller method
href="resources/css/test.css"
'<script src="resources/js/test.js"></script>'
Test.php controller and TestModel.php only exists to serve as an example on how to use a controller and a model in Sapling. Database are not needed as long as you don't load a model in your controller.
- Url Routing
- Security against script access
- Secured database credentials
- Simple debugger
- Flexible query builder
- Simple folder structure
- Easy to use and understand
- Documented
- Better routing implementation, similar to of Laravel or Codeigniter
- API implementation