protected static function actionLogin() { if (empty($_POST)) { self::redirect(App::getLink('Auth')); } $errors = array(); if (empty($_POST['email'])) { $errors['email'] = App::t('Введите email'); } else { if (!preg_match('/^[-A-Za-z0-9_\\.]+@[-A-Za-z0-9_\\.]+\\.[a-z0-9]{2,4}$/', $_POST['email'])) { $errors['email'] = App::t('Некорректный email'); } } if (empty($_POST['password'])) { $errors['password'] = App::t('Введите пароль'); } if (empty($errors)) { $user = UserModel::getByEmail($_POST['email']); if (!$user) { $errors['email'] = App::t('Пользователь не найден'); } if ($user->password == md5($_POST['password'])) { App::currentUser($user); self::redirect('/'); } else { $errors['password'] = App::t('Неверный пароль'); } } }
protected static function actionNew() { $product = new ProductModel(null, 0); $errors = self::processPost($product); self::assignForm($product, $errors); self::templateVar('title', App::t('Создание товара')); return self::displayPage('admin'); }
protected static function actionDefault() { $categories = new Collection('Category', App::currentLang()->getId()); $list = new TemplateList(); $list->fields = array('id' => array('type' => 'id', 'title' => 'Номер'), 'name' => array('type' => 'text', 'title' => 'Название'), 'active' => array('type' => 'active', 'title' => 'Вкл/Выкл', 'action' => 'active', 'controller' => 'admin-categories')); $list->itemActions = array('edit' => array('hint' => 'Изменить', 'icon' => 'edit', 'controller' => 'admin-categories'), 'delete' => array('hint' => 'Удалить', 'icon' => 'delete', 'controller' => 'admin-categories')); $list->actions = array('new' => array('hint' => 'Добавить', 'icon' => 'add', 'controller' => 'admin-categories')); $list->items = $categories->items(); $list->classes = 'center-list'; self::templateVar('title', App::t('Категории')); self::templateVar('content', $list); return self::displayPage('admin'); }
protected static function actionAdd() { if (!empty($_GET['product'])) { if (isset($_SESSION['cart'][$_GET['product']])) { $_SESSION['cart'][$_GET['product']] += $_GET['quantity']; } else { $_SESSION['cart'][$_GET['product']] = $_GET['quantity']; } if ($_SESSION['cart'][$_GET['product']] == 0) { unset($_SESSION['cart'][$_GET['products']]); } } if (App::isAjax()) { return App::t('Товар успешно добавлен'); } }
/** * @throws \yii\web\NotFoundHttpException * @return string */ public function run() { if ($this->pageId === null) { $this->pageId = Yii::$app->request->get('pageId'); } if (!is_null($this->pageId)) { $model = CmsModel::findOne($this->pageId); if ($model) { $model->content = $this->parseBaseTemplateParams($model->content); if (!empty($this->layout)) { $this->controller->layout = $this->layout; } return $this->controller->render($this->view, ['model' => $model]); } } throw new NotFoundHttpException(App::t('yii2mod', 'The requested page does not exist.')); }
public function actionUpdate($name) { if ($name == 'admin') { \App::$app->session->setFlash('success', \App::t('app', 'The Administrator has all permissions')); return $this->redirect(['view', 'name' => $name]); } $model = $this->findModel($name); if ($model->load(\App::$app->request->post())) { $permissions = $this->preparePermissions(Yii::$app->request->post()); if ($model->updateRole($name, $permissions)) { \App::$app->session->setFlash('success', " '{$model->name}' " . \App::t('app', 'successfully updated')); return $this->redirect(['view', 'name' => $name]); } } else { $permissions = $this->getPermissions(); $model->loadRolePermissions($name); return $this->render('update', ['model' => $model, 'permissions' => $permissions]); } }
"><?php echo App::t('Категории'); ?> </a></li> <li><a class="<?php echo App::getController() == 'AdminBrands' ? 'active' : ''; ?> " href="<?php echo App::getLink('AdminBrands'); ?> "><?php echo App::t('Производители'); ?> </a></li> <li class="logout"><a href=""><?php echo App::t('Logout'); ?> </a></li> </ul> </nav> <ul class="langs-list clear"> <?php foreach (App::getLangs() as $lang) { ?> <li><a class="<?php echo $lang->getId() == App::currentLang()->getId() ? 'active' : ''; ?> " data-lang="<?php echo $lang->code; ?>
/** * Finds the CmsModel model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * * @param integer $id * * @return CmsModel the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = CmsModel::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException(App::t('yii2mod', 'The requested page does not exist.')); } }
?> <input type="password" name="confirm" placeholder="<?php echo App::t('Confirm'); ?> "> <?php if ($this->registration_errors && !empty($this->registration_errors['confirm'])) { ?> <span class="error"><?php echo $this->registration_errors['confirm']; ?> </span><?php } ?> <button type="submit" class="btn btn-default"><?php echo App::t('Регистрация'); ?> </button> </form> </div> </div> </div> </div> </section> <?php echo $this->displayTemplate('chunks/footer'); ?> </div> <?php echo $this->displayTemplate('chunks/scripts');