This project is mostly about creating a framework that is going to be the foundation of any small scale system. It is intended to be used specifically for the ERP system.
This framework is intended to reduce if not eliminate problems that most programmer face such as:
Through carefully designing the codebase and the functions, tasks that are normally repeated such as creating a connection object every time you needed to connect to the database and more.
Though the framework's structure and design, the developer can easily create an application using the inbuilt and ready to go functions.
With collaboration in mind, the framework has been designed to enable easy and swift collaboration with your team.
Easy setup migrations and share them for your team to use easily. Share your controllers and views without breaking anything.
This framework depends on:
- php 7.0 and above
PHP 5.4 and above has an inbuilt server used for development. We can start this server by running.
php server start from the terminal
core framework
- cd to routes directory, open routes.php file
- add routes.
<?php
use Core\Router\Route;
Route::get('', 'AboutController@hello');
Route::get('hello/', 'AboutController@index');
Route::get('hello/{id}','AboutController@withParam');
Route::get('help', 'AboutController@help');
Route::post('file', 'AboutController@file');
Route::get('test',function(){
echo "this is a test";
});
Route::get('user/{id}',function($id){
echo $id;
});
?>
use Core\Requests\Request;
...
public function getData()
{
$request = new Request(); //create a new request
//get the field value
$request->fieldname;
}
use Core\Requests\Request;
$f = $request->files('file', 'file1'); //get the files if any from the request using field names. Retrieves all the files mentioned
$g = $request->file('file'); //get the file if any from the request using field name. Retrieves one file
dump($f->file); //access the file
dump($f->file->size); //get the file attributes
dump($g->size); //get the file attributes. Attributes: name|tmp_name|size|type|error `
//to store files publicly
use Core\Exceptions\ExceptionsHandler;
use Core\Requests\Request;
use Core\Storage\Storage;
...
$request = new Request();
$f = $request->files('file', 'file1');//if multiple files uploaded
//$f=$requst->file('file');//if only one file uploaded
try {
$storage=new Storage();
//store files privately.
//Takes one or two params: $file,[$destinationDir|optional].
//Only accessible via Storage methods: download(),getPrivate()
$storage->put($f->file);
//stores file publicly. Can be accessed as an asset
$storage->store($file);
echo "file uploaded successfully";
} catch (ExceptionsHandler $e) {
//handle errors if any
dd($e);
}
From the terminal run
php server make migration|table='name'
- name : is the name of your migration
The migration will be created in Database/Migrations directory.
<?php
namespace App\Migrations;
use Core\Database\SchemaBuilder\Schema;
class test{
public static function run($tablename)
{
$table = new Schema($tablename);
$table->increments(); //autoincrement primary key
## add table fields here
$table->varchar('name',15);
$table->build();
}
}
To execute the migrations, run
php server migrate
Instead of defining all of your request handling logic as Closures in route files, you may wish to organize this behavior using Controller classes. Controllers can group related request handling logic into a single class. Controllers are stored in the App/Controllers directory.
A basic controller can be created using the terminal
php server make controller='name'
This creates a basic controller in the App/Controllers directory with the filename 'name';
asset('name');
view('viewname')
view('viewname',['key'=>'value',...])
<article>
{{name}}
{id}
[title]
</article>
Use of placeholders only works if the values are not arrays/objects
<article>
<?php
##handle arrays/objects here
?>
</article>
Arrays/objects can be accessed as above. More simpler solutions are coming soon
Views are stored in the App\Views directory and have a .php extension.
Configuration details such as api keys/ SMTP settings/ Database setting are best stored in a config.ini file located in Config/ directory.
[mail] ## specifies the name of the configuration. i.e 'mail' for mail settings
smtp_server=smtp.mail.com
port=443
username=user
password=password
The configuration can be accessed by using the Config class
use Core\Config\Config;
//lets get the database settings
Config::database(); ## access it statically
//access it dynamically
$config=new Config;
dd($config->database());