'user' => [
'identityClass' => 'common\models\User',
'loginUrl' => '/site/login',
'identityCookie' => [
'name' => '_identity-frontend',
],
],
'modules' => [
'api1' => [
'class' => 'api\modules\Api1',
'components' => [
'user' => [
'identityClass' => 'common\models\Api1User',
'loginUrl' => '/site/login',
'identityCookie' => [
'name' => '_identity-api1',
],
],
]
],
'api2' => [
'class' => 'api\modules\Api2',
'components' => [
'user' => [
'identityClass' => 'common\models\Api2User',
'loginUrl' => '/site/login',
'identityCookie' => [
'name' => '_identity-api2',
],
],
]
],
]
'filter' => DatePicker::widget([
'model' => $searchModel,
'attribute' => 'created_start',
'attribute2' => 'created_end',
'separator' => '-',
'type' => DatePicker::TYPE_RANGE,
'pluginOptions' => ['format' => 'yyyy-mm-dd'],
'options' => ['autocomplete' => 'off'],
'options2' => ['autocomplete' => 'off'],
]),
is_old = true
is_old = false
, а при существовании записи в базе - обновляем is_old = false
, затем далее удаляем все записи с is_old = true
'components' => [
'request' => [
'csrfParam' => '_csrf-api',
'parsers' => [
'application/json' => [
'class' => \yii\web\JsonParser::class,
'asArray' => true,
],
],
],
// ...
{
"name": "Nick"
}
$name = Yii::$app->request->post('name')
будет работать. Route::get('/', 'Equip@allItems');
Route::get('equipment', 'Equip@allEquipmentItems');
private function allItemsInternal(string $template){
return view($template, [
'all' => $this->eqs(),
'types' => $this->types()
]);
}
public function allItems(){
return $this->allItemsInternal('all');
}
public function allEquipmentItems(){
return $this->allItemsInternal('equipment');
}
class A {
public function checkOperation() {
throw new ADomainException;
}
}
class B {
public function checkMission() {
throw new BDomainException;
}
}
try {
$this->mObj->checkOperation();
$this->mObj->checkMission();
} catch (ADomainException $e) {
$this->alertRedirect('danger', $e->getMessage(), '/operations');
} catch (BDomainException $e) {
$this->alertRedirect('danger', $e->getMessage(), "/operation-{$this->mObj->oid}/missions");
}
@var App\Contracts\MyInterface
для свойства какого-то класса, это даёт вам понять, что ничего более (кроме того, что есть в интерфейсе) в этом классе от этого свойства вам не понадобиться.class ShapeHandler {
/**
* @var ShapeInterface
*/
private $shape;
public function __construct(ShapeInterface $shape) {
$this->shape = $shape;
}
public function getShapeSize() : float {
return $this->shape->getSize();
}
}
interface ShapeInterface {
public function getSize() : float;
}
class Circle implements ShapeInterface {
private $radius;
public function getSize() : float {
return MATH_PI * pow($this->radius, 2);
}
public function getLength() : float {
return MATH_PI * 2 * $this->radius;
}
}
class Rectangle implements ShapeInterface {
private $height;
private $width;
public function getSize() : float {
return $this->height * $this->width;
}
public function getPerimetr() : float {
return 2 * ($this->height + $this->width);
}
}
$circle = new Circle();
$circle->setRadius(10);
$shapeHandler = new ShapeHandler($circle);
$shapeHandler->getShapeSize();
$rectangle = new Rectangle();
$rectangle->setHeight(5);
$rectangle->setWidth(20);
$shapeHandler = new ShapeHandler($rectangle);
$shapeHandler->getShapeSize();
interface SoftDeletableInterface
{
public function softDelete() : bool;
public function getChildren() : array;
}
abstract class SoftDeletableModel extends ActiveRecord implements SoftDeletableInterface
{
public function getChildren() : array
{
return [];
}
final public function softDelete(bool $inTransaction = false) : bool
{
if ($inTransaction) {
$this->softDeleteInternal();
return true;
}
$transaction = \Yii::$app->db->beginTransaction();
try {
$this->softDeleteInternal();
$transaction->commit();
return true;
} catch (\Exception $exception) {
$transaction->rollBack();
return false;
}
}
private function softDeleteInternal() : void
{
$this->updateAttributes(['is_deleted' => true]);
foreach ($this->getChildren() as $children) {
foreach ((array)$children as $child) {
$child->softDelete(true);
}
}
}
}
class Category extends SoftDeletableModel
{
public function getChildren() : array
{
return $this->groups;
}
public function getGroups()
{
return $this->hasMany(Group::class, ['category_id' => 'id']);
}
}
class Group extends SoftDeletableModel
{
public function getChildren() : array
{
return [$this->services, $this->users] /* array of array */;
}
public function getServices()
{
return $this->hasMany(Service::class, ['group_id' => 'id']);
}
public function getUsers()
{
return $this->hasMany(User::class, ['group_id' => 'id']);
}
}
class Service extends SoftDeletableModel
{
}
class User extends SoftDeletableModel
{
}