1. Go to this page and download the library: Download pribolshoy/yii2-repository 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/ */
pribolshoy / yii2-repository example snippets
namespace app\repositories;
use pribolshoy\yii2repository\repositories\AbstractARRepository;
use app\models\User;
class UserRepository extends AbstractARRepository
{
protected ?string $model_class = User::class;
protected function defaultFilter()
{
$this->addFilterValueByParams('status', 'active');
$this->addFilterValueByParams('limit', 25);
$this->addFilterValueByParams('page', 1);
}
protected function addQueries()
{
if ($this->existsFilter('status')) {
$this->getQueryBuilder()->andWhere(['status' => $this->getFilter('status')]);
}
if ($this->existsFilter('email')) {
$this->getQueryBuilder()->andWhere(['like', 'email', $this->getFilter('email')]);
}
return $this;
}
}
namespace app\services;
use pribolshoy\yii2repository\services\AbstractARService;
use app\repositories\UserRepository;
class UserService extends AbstractARService
{
protected ?string $repository_class = UserRepository::class;
protected function init()
{
// Инициализация сервиса
}
}