A powerful PHP Framework in PHP 8.4 - Beautiful code & Elegant syntax
SGBDR: Compatible with MySQL / MariaDB / PostgreSQL
This Open Source Framework is developed by Stephen Damian
Here you have the source codes of the skeleton
.
The kernel
source codes for this Framework are in this package:
Damian PHP Framework - Kernel - [damian-php-fw]
- PHP
8.2
||8.3
||8.4
- You can create a new project via the
composer create-project
command:
composer create-project s-damian/damian-php example-app-name
- Create your
.env
file:
cd /your-path/example-app-name
cp .env.example .env
- You have to configure the
.env
file.
- You have to configure your web server (Linux / Nginx or Apache / MySQL or PostgreSQL / PHP).
You have an example Nginx Vhost configuration in docs/nginx/vhost-example.conf
file.
- http://www.your-domain.com
- http://www.your-domain.com/contact
- http://www.your-domain.com/blog
- http://www.your-domain.com/blog/slug-1
- http://www.your-domain.com/callable-example
- http://www.your-domain.com/sitemap
- The documentation for this Framework is in
docs/DamianPhp
folder.
An example of a route listing:
<?php
Router::group(['namespace' => 'Front\\', 'prefix' => 'website'], function () {
Router::post(
'/contact',
'Contact@sendMail',
['name' => 'contact_send-mail']
);
Router::group(['prefix' => '/blog'], function () {
Router::get(
'',
'Article@index',
['name' => 'article_index']
);
Router::get(
'/{slug}',
'Article@show',
['name' => 'article_show']
);
});
});
Retrieve a URL with the name of a route:
<?php echo route('article_show', ['slug' => $article->slug]); ?>
Example to insert an article (using the setters
magic methods):
<?php
$article = new Article();
$article->setTitle('Article 1');
$article->setDescription('Description');
$article->setContent('Content');
$article->setSlug('slug-1');
$article->save();
Example to update an article (using the fill
magic method):
<?php
$article = Article::load()->findOrFail($id);
$article->fill(Request::getPost()->all());
$article->save();
Example using the when
magic method:
<?php
$articles = Article::load()
->select('title, description, content')
->where('slug', '!=', 'article-2')
->when((int) Input::get('status') === 1, function ($query) {
return $query->where('status', '=', 1);
})
->findAll();
To paginate an item listing:
<?php
$article = new Article();
$articles = $article->where('status', '=', 1)->paginate(20);
$pagination = $article->getPagination();
foreach ($articles as $article) {
echo $article->title;
}
echo $pagination->render();
echo $pagination->perPageForm();
<?php
$pagination = new Pagination();
$pagination->paginate($countElements);
$limit = $pagination->getLimit();
$offset = $pagination->getOffset();
// Here your list of items with a loop.
echo $pagination->render();
echo $pagination->perPageForm();
Validation example (you can do method injection):
<?php
public function update(Validator $validator, int $id)
{
$validator->rules([ // Add your rules in the array.
'title' => ['max' => 190, 'required' => true],
'description' => ['max' => 190, 'required' => true],
'content' => ['required' => true],
]);
if ($validator->isValid()) {
// Success
} else {
// Error
$validator->getErrorsHtml();
}
}
You can add custom validation rules. Example:
<?php
Validator::extend('strictly_equal', function ($input_name, $input_value, $parameters) {
return (string) $input_value === (string) $parameters;
});