This software aims to be engaged in any system and without any additional line programming is required, the final code is automatically optimized.
- Automatic create Entities from Doctrine
- Automatic create default routes to REST
- Automatic generate your Form to REST
Add these lines to your composer.json:
"require": {
"controleonline/rest-essentials": "*"
}
Default settings
<?php
$config = array(
'APP_ENV' => 'production', //Default configs to production or development
);
In your config/autoload/database.local.php confiruration add the following:
<?php
return array(
'doctrine' => array(
'connection' => array(
'orm_default' => array(
'driverClass' => 'Doctrine\DBAL\Driver\PDOMySql\Driver',
'params' => array(
'host' => 'localhost',
'port' => '3306',
'user' => 'user',
'password' => 'pass',
'dbname' => 'db',
'driver' => 'pdo_mysql',
'charset' => 'utf8',//Very important
'driverOptions' => array(
1002=>'SET NAMES utf8' //Very important
)
)
)
)
)
);
In your config/application.config.php confiruration add the following:
<?php
$modules = array(
'RESTEssentials'
);
return array(
'modules' => $modules,
'module_listener_options' => array(
'module_paths' => array(
'./module',
'./vendor',
),
'config_glob_paths' => array(
'config/autoload/{,*.}{global,local}.php',
),
),
);
In your module.config.php file:
<?php
namespace YourNameSpace;
return array(
'RESTEssentials' => array(
//Configs of RESTEssentials here
)
);
Get return from your Controller via Ajax:
$.ajax({
headers: {
Accept: "application/json; charset=utf-8",
"Content-Type": "application/json; charset=utf-8"
},
url:'http://localhost/<Module>/<Controller>/<Action>/<Parameters>',
data: "data",
success: function (response) {
console.log(response);
}});
Or simply add the .json suffix at the end of the URL:
http://localhost/<Module>/<Controller>/<Action>.json?<Parameters>
To return directly your Entity, use the REST standard
http://localhost/<Entity>/id/<ID>.json?<Parameters> //Find By ID
http://localhost/<Entity>.json?<Parameters> //Return all records
http://localhost/<Entity>/id/<ID>/<Children>.json?<Parameters> //Find By Parent ID
http://localhost/<Entity>.json?page=2&limit=100 //Return second page limited by 100 records
If the browser does not support PUT, DELETE and OPTIONS use :
http://localhost/<Entity>.json?method=PUT //Return second page limited by 100 records