interface StatusListable
{
public function getStatusName(): string;
}
trait StatusReturner
{
public static function getStatusDescriptions()
{
return [
self::STATUS_NOT_PAID => 'Не оплачено',
self::STATUS_PAID => 'Оплачено',
self::STATUS_CANCEL => 'Отменена',
];
}
public function getStatusName($status): string
{
return ArrayHelper::getValue(self::getStatusDescriptions(), $status);
}
}
abstract CrudController extends Controller {
public $modelClass;
public $searchModelClass;
public function actionIndex(){
$searchModel = new $this->searchModel;
// ...
}
public function actionView($id){
$model = $this->findModel($id);
// ...
return $this->render('view', ['model' => $model]);
}
public function actionCreate(){
$model = new $this->modelClass;
// ...
}
public function actionUpdate($id){
$model = $this->findModel($id);
// ...
}
public function actionDelete($id){
$model = $this->findModel($id);
// ...
}
private function findModel($id){
$modelCLass = new $this->modelClass;
$model = $modelClass::findOne($id);
// ...
return $model;
}
}
class ProductController extends CrudController {
public $modelClass = '\app\common\models\Product';
public $searchModelClass = '\backend\modules\product\models\Product';
}
class ItemController extends CrudController {
public $modelClass = '\app\common\models\Item';
public $searchModelClass = '\backend\modules\product\models\Item';
}
abstract CrudController extends Controller {
public $permissions = [
'index' => null,
'view' => null,
'create' => null,
'update' => null,
'delete' => null,
];
// ...
public function actionView(){
if (isset($this->permissions['view']) && !Yii::$app->user->can($this->permissions['view']){
throw new ForbiddenException();
}
}
}
class ProductController extends CrudController {
public $permissions = [
'index' => 'indexProduct',
'view' => 'viewProduct',
//...
];
}
class ItemController extends CrudController {
public function beforeAction() {
$this->permissions = array_merge(parent::$permissions, [
'view' => 'viewItem',
]);
return parent::beforeAction();
}
}
abstract CrudController extends Controller {
public $scenarios = [
'index' => Model::SCENARIO_DEFAULT,
'view' => Model::SCENARIO_DEFAULT,
'create' => Model::SCENARIO_DEFAULT,
'update' => Model::SCENARIO_DEFAULT,
'delete' => Model::SCENARIO_DEFAULT,
];
public function actionView($id){
$model = $this->findModel($id);
$model->scenario = $this->scenario['view'];
}
// ...
}
class ProductController extends CrudController {
public function beforeAction() {
$this->scenarios['view'] = Product::SCENARIO_VIEW;
return parent::beforeAction();
}
}
http://site.com/composer.json
возвращает то что надо?<form method="post">
<input name="name">
<input name="question[0][name]">
<input name="question[0][answer][]">
<input name="question[0][answer][]">
<input name="question[0][correct_answer]">
<input name="question[1][name]">
<input name="question[1][answer][]">
<input name="question[1][answer][]">
<input name="question[1][correct_answer]">
<input type="submit" value="save">
</form>
var_dump($_POST);
array (size=2)
'name' => string '' (length=0)
'question' =>
array (size=2)
0 =>
array (size=3)
'name' => string '' (length=0)
'answer' =>
array (size=2)
0 => string '' (length=0)
1 => string '' (length=0)
'correct_answer' => string '' (length=0)
1 =>
array (size=3)
'name' => string '' (length=0)
'answer' =>
array (size=2)
0 => string '' (length=0)
1 => string '' (length=0)
'correct_answer' => string '' (length=0)
if
и foreach
.<?php if (count($arResult["ERRORS"]) > 0) : ?>
<?php foreach ($arResult["ERRORS"] as $key => $error) : ?>
<?php if (intval($key) == 0 && $key !== 0) : ?>
<div class="alert alert-danger" role="alert">
<?php
$arResult["ERRORS"][$key] = str_replace("#FIELD_NAME#", """.GetMessage("REGISTER_FIELD_".$key).""", $error);
ShowError(implode("<br />", $arResult["ERRORS"]));
?>
</div>
<?php elseif ($arResult["USE_EMAIL_CONFIRMATION"] === "Y") : ?>
<p><?php echo GetMessage("REGISTER_EMAIL_WILL_BE_SENT") ?></p>
<?php endif; ?>
<?php endforeach; ?>
<?php endif ?>
class SiteController extends yii\web\Controller {
public function actionFiles($name){
if (null === $file = File::findOne(['name' = $name])){
throw new NotFoundHttpException('File not found');
}
return $file->path;
}
}
'patterns' => [
'GET,HEAD /files/<name>' => 'site/files',
],