Wallogit.com
2017 © Pedro Peláez
The Atl Framework.
Framework MVC for team, (*1)
Composer Download., (*2)
``` bash $ composer install, (*3)
## Load view ```php View('layout/header')
Main index, (*4)
``` php $route->get('/','MainController@index');, (*5)
Route Get ``` php $route->get('/id/{id}', 'MainController@checkRouteGet');
Route Post, (*6)
``` php $route->post('/validate','MainController@checkRoutePost');, (*7)
Route validate int ``` php $route->get('/id/{id}', 'MainController@checkRoutePost', array('page' => '\d+'));
Exemple detail., (*8)
``` php, (*9)
use Atl\Validation\Validation; $validator = new Validation;, (*10)
$validator->add( array(, (*11)
// the key is in the form [field]:[label]
'name:Name' => 'required',
// you can have multiple rules for the same field
'email:Your email' => 'required | email',
// validators can have options
'message:Your message' => 'required | minlength(10)',
// and you can overwrite the default error message
'phone:Phone' => 'regex(/your_regex_here/)(This field must be a valid US phone number)'
)
);, (*12)
if ($validator->validate($_POST)) {, (*13)
// send notifications to stakeholders // save the form data to a database
} else {, (*14)
// send the error messages to the view
$view->set('errors', $validator->getMessages();
}, (*15)
## Session; Handle session. ``` php // Config file config/app.php 'session' => array( 'status' => true, 'storage' => ''), // Use code base Session()->set('name','Test Session'); echo Session()->get('name'); // Session flash Session()->getFlashBag()->set('name', 'Test'); var_dump(Session()->getFlashBag()->has('name')); var_dump(Session()->getFlashBag()->get('name'));
Handle redirect url., (*16)
``` php, (*17)
redirect( url('exemple/id/1') );, (*18)
## __ ; ``` php
use Atl\Pagination\Pagination;
$ofset = 10; // Result query row number.
$config['pageStart'] = $page; // Number of page.
$config['ofset'] = $ofset;
$config['totalRow'] = 50; // Number of count total row.
$config['baseUrl'] = url('/page/'); // Url base of pagination.
$pagination = new Pagination($config);
echo $pagination->link( $config );
Use model static, (*19)
``` php DB()->insert("account", [ "user_name" => "foo", "email" => "foo@bar.com" ]);, (*20)
DB()->update("account", [ "user_name" => "foo", "email" => "foo@bar.com" ],[ "id" => 1 ]);, (*21)
DB()->select("account", [ "user_name", "email" ], [ "user_id[>]" => 100 ]);, (*22)
DB()->select("account", "user_name", [ "email" => "foo@bar.com" ]); // WHERE email = 'foo@bar.com', (*23)
DB()->select("account", "user_name", [ "user_id" => 200 ]); // WHERE user_id = 200, (*24)
DB()->select("account", "user_name", [ "user_id[>]" => 200 ]); // WHERE user_id > 200, (*25)
DB()->select("account", "user_name", [ "user_id[>=]" => 200 ]); // WHERE user_id >= 200, (*26)
DB()->select("account", "user_name", [ "user_id[!]" => 200 ]); // WHERE user_id != 200, (*27)
DB()->select("account", "user_name", [ "age[<>]" => [200, 500] ]); // WHERE age BETWEEN 200 AND 500, (*28)
DB()->select("account", "user_name", [ "age[><]" => [200, 500] ]); // WHERE age NOT BETWEEN 200 AND 500, (*29)
// [><] and [<>] is also available for datetime DB()->select("account", "user_name", [ "birthday[><]" => [date("Y-m-d", mktime(0, 0, 0, 1, 1, 2015)), date("Y-m-d")] ]); //WHERE "create_date" BETWEEN '2015-01-01' AND '2015-05-01' (now), (*30)
// You can use not only single string or number value, but also array DB()->select("account", "user_name", [ "OR" => [ "user_id" => [2, 123, 234, 54], "email" => ["foo@bar.com", "cat@dog.com", "admin@medoo.in"] ] ]); // WHERE // user_id IN (2,123,234,54) OR // email IN ('foo@bar.com','cat@dog.com','admin@medoo.in'), (*31)
// [Negative condition]
DB()->select("account", "user_name", [
"AND" => [
"user_name[!]" => "foo",
"user_id[!]" => 1024,
"email[!]" => ["foo@bar.com", "cat@dog.com", "admin@medoo.in"],
"city[!]" => null,
"promoted[!]" => true
]
]);
// WHERE
// user_name != 'foo' AND
// user_id != 1024 AND
// email NOT IN ('foo@bar.com','cat@dog.com','admin@medoo.in') AND
// city IS NOT NULL
// promoted != 1, (*32)
// Or fetched from select() or get() function DB()->select("account", "user_name", [ "user_id" => DB()->select("post", "user_id", ["comments[>]" => 40]) ]); // WHERE user_id IN (2, 51, 321, 3431), (*33)
```, (*34)