Patika is a routing package which you don't have to define the routes.
There are a lot of cool routing packages in PHP World. But you have to define all routes that you need it. But sometimes like creating an API, it is time waste. When you use the Patika, you don't have to define any route. All routes are parsed by the Patika according to your Controller definitions.
GET localhost/users/all
# Namespace: App\Controllers\Users
# Method: all
# Arguments: []
GET localhost/admin/manager/users/all
# Namespace: App\Controllers\Admin\Manage\Users
# Method: all
# Arguments: []
GET localhost/admin/manage/users/get/1
# Namespace: App\Controllers\Admin\Manage\Users
# Method: get
# Arguments: [1]
namespace App\Controllers\Admin\Manage;
class Users {
public function get($id)
{
echo $id;
}
}
GET localhost/admin/manage/users/getByArgument/1/2/3/foo/bar
# Namespace: App\Controllers\Admin\Manage\Users
# Method: get
# Arguments: [1, 2, 3, 'foo', 'bar']
namespace App\Controllers\Admin\Manage;
class Users {
public function get($one, $two, $three, $foo, $bar)
{
echo $id;
}
}
To install through composer, simply put the following in your composer.json
file:
{
"require": {
"ozziest/patika": "dev-master"
}
}
$ composer update
First of all, you should define .htaccess
file so that handle all request and send it to index.php
file.
.htaccess
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
index.php
file must be defined like this;
// Including composer autoload file
include 'vendor/autoload.php';
// First of all, you should use try-catch block for handling routing errors
try {
// You must create a new instance of Manager Class with the app argument.
$patika = new Ozziest\Patika\Manager(['app' => 'App\Controllers']);
// And calling the route!
$patika->call();
} catch (Ozziest\Patika\Exceptions\PatikaException $e) {
// If the controller or method aren't found, you can handle the error.
echo $e->getMessage();
}
That's all! Patika Router is active now. Now, you can define your controller which what you want.
Having trouble with The Patika? Check out our and we’ll help you sort it out.