PHP code example of s-damian / damian-php

1. Go to this page and download the library: Download s-damian/damian-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

s-damian / damian-php example snippets




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']
        );
    });
});


 echo route('article_show', ['slug' => $article->slug]); 



$article = new Article();
$article->setTitle('Article 1');
$article->setDescription('Description');
$article->setContent('Content');
$article->setSlug('slug-1');
$article->save();



$article = Article::load()->findOrFail($id);
$article->fill(Request::getPost()->all());
$article->save();



$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();



$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();



$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();



public function update(Validator $validator, int $id)
{
    $validator->rules([ // Add your rules in the array.
        'title' => ['max' => 190, '// Success
    } else {
        // Error
        $validator->getErrorsHtml();
    }
}



Validator::extend('strictly_equal', function ($input_name, $input_value, $parameters) {
    return (string) $input_value === (string) $parameters;
});