[
'label' => 'Executive Name',
'attribute' => 'cs.first_name',
'visible' => function ($data) {
if ($data->hc_customersupport->is_supervisor) {
return '1'; // or return true;
} else {
return '0'; // or return false;
}
},
],
use Yii;
...
'visible' => Yii::$app->user->can('supervisor'),
'as beforeAction' => function () {
//Тут ваши действия для анонимной функции
}
'as beforeAction' => [
'class' => app\modules\users\behaviors\LastVisitBehavior::class
],
Url::current(['ref' => null]);
/**
* Страница сохранения реферера (пригласившего)
*
* @param int $id
*
* @return Response|string
*/
public function actionReferral(int $id)
{
if (Yii::$app->user->isGuest) {
ReferralHelper::setReferrerId($id);
}
return $this->redirect('site/registration');
}
/**
* Страница регистрации
*
* @return Response|string
* @throws \yii\base\InvalidArgumentException
* @throws \yii\db\Exception
*/
public function actionRegistration()
{
if (!Yii::$app->user->isGuest) {
return $this->goHome();
}
$userForm = new UserForm();
if ($userForm->load(Yii::$app->request->post())) {
$referrerId = ReferralHelper::getReferrerId();
$referrer = $referrerId !== null ? $this->getUser((int)$referrerId) : null;
$userForm->setReferrer($referrer);
if ($userForm->save() && $userForm->login()) {
$message = 'Спасибо за регистрацию.';
if ($referrer !== null) {
$message .= ' Вас пригласил ' . $referrer;
}
Yii::$app->session->setFlash('success', $message);
ReferralHelper::removeReferrer();
return $this->goHome();
}
$this->addErrorForForm($userForm);
}
$userForm->password = '';
return $this->render('registration', [
'model' => $userForm,
]);
}
class ReferralHelper
{
const KEY_REFERRER_ID = 'referrer_id';
public static function setReferrerId(int $referrerId)
{
\Yii::$app->getSession()->set(self::KEY_REFERRER_ID, $referrerId);
}
public static function getReferrerId()
{
return \Yii::$app->getSession()->get(self::KEY_REFERRER_ID, null);
}
public static function removeReferrer()
{
return \Yii::$app->getSession()->remove(self::KEY_REFERRER_ID);
}
}
return [
'viewPath' => '@app/modules/users/views/frontend',
];
return [
'components' => [
'view' => [
'theme' => [
'basePath' => '@app/themes/basic',
'baseUrl' => '@web/themes/basic',
'pathMap' => [
'@app/views' => '@app/themes/basic',
],
],
],
],
];
return [
'modules' => [
'users' => [
'class' => app\modules\users\Module::class,
'controllerNamespace' => 'app\modules\users\controllers\frontend',
'viewPath' => '@app/modules/users/views/frontend',
'layout' => '@app/views/layouts/column2-right.php',
],
]
'modules' => [
'api' => [
'class' => app\modules\api\Module::class,
'modules' => [
'v1' => [
'class' => app\modules\api\modules\v1\Module::class,
'controllerMap' => [
'organizations' => \app\modules\organizations\api\controllers\DefaultController::class,
'users' => \app\modules\users\api\Controllers\DefaultController::class,
'cities' => \app\modules\api\modules\v1\controllers\events\CitiesController::class,
],
]
],
],
],
class DefaultController extends ActiveController
{
public $modelClass = Organization::class;
public $serializer = [
'class' => 'yii\rest\Serializer',
'collectionEnvelope' => 'items',
];
public function behaviors()
{
$behaviors = parent::behaviors();
$behaviors['contentNegotiator']['formats']['text/html'] = Response::FORMAT_JSON;
return $behaviors;
}
public function actions()
{
$actions = parent::actions();
unset($actions['delete'], $actions['create'], $actions['view']);
return $actions;
}
}
[
'class' => 'yii\rest\UrlRule',
'controller' => ['api/v1/organizations'],
'extraPatterns' => [
'GET, POST find' => 'find',
],
],
'components' => [
'response' => [
// ...
'formatters' => [
\yii\web\Response::FORMAT_JSON => [
'class' => yii\web\JsonResponseFormatter::class,
'prettyPrint' => YII_DEBUG, // используем "pretty" в режиме отладки
'encodeOptions' => JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE,
],
],
],
'as contentNegotiator' => [
'class' => \yii\filters\ContentNegotiator::class,
'formatParam' => '_format',
'formats' => [
'application/json' => \yii\web\Response::FORMAT_JSON,
'application/octet-stream' => \yii\web\Response::FORMAT_JSON,
'text/html' => \yii\web\Response::FORMAT_JSON,
'application/xml' => \yii\web\Response::FORMAT_XML,
],
],
],
'controllerMap' => [
'elfinder' => [
'class' => 'mihaildev\elfinder\PathController', /////ВОТ ЗДЕСЬ ДОЛЖНО БЫТЬ!
'access' => ['@'],
'root' => [
'baseUrl'=>'/web',
// 'basePath'=>'@webroot',
'path' => 'upload/global',
'name' => 'Global'
],
]
],
$dataProvider = new ActiveDataProvider([
'query' => $query,
'sort'=> [
'attributes' => [
'age',
'name' => [
'asc' => ['first_name' => SORT_ASC, 'last_name' => SORT_ASC],
'desc' => ['first_name' => SORT_DESC, 'last_name' => SORT_DESC],
'default' => SORT_DESC,
'label' => 'Name',
],
],
]);