本文整理汇总了PHP中yii\helpers\Url::previous方法的典型用法代码示例。如果您正苦于以下问题:PHP Url::previous方法的具体用法?PHP Url::previous怎么用?PHP Url::previous使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\helpers\Url
的用法示例。
在下文中一共展示了Url::previous方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getCreateUpdateResponse
/**
* @param ActiveRecord $model
* @param array $actions Custom actions array in the form of
* ```php
* 'name' => function() {
*
* }
* ```
* @param bool $addDefaultActions If true default actions will be added
* @return \yii\web\Response
* @throws BadRequestHttpException
*/
protected function getCreateUpdateResponse($model, $actions = [], $addDefaultActions = true)
{
$defaultActions = [AdminHtml::ACTION_SAVE_AND_STAY => function () use($model) {
/** @var Controller | CrudControllerTrait $this */
return $this->redirect(['update', 'id' => $model->getPrimaryKey()]);
}, AdminHtml::ACTION_SAVE_AND_CREATE => function () use($model) {
/** @var Controller | CrudControllerTrait $this */
if ($url = Url::previous($this->createUrlParam)) {
Url::remember(null, $this->createUrlParam);
return $this->redirect($url);
}
return $this->redirect(['create']);
}, AdminHtml::ACTION_SAVE_AND_LEAVE => function () use($model) {
/** @var Controller | CrudControllerTrait $this */
if ($url = \Yii::$app->request->get('return')) {
return $this->redirect($url);
}
if ($url = Url::previous($this->indexUrlParam)) {
Url::remember(null, $this->indexUrlParam);
return $this->redirect($url);
}
return $this->redirect(['index']);
}];
if ($addDefaultActions) {
$actions = array_merge($defaultActions, $actions);
}
$actionName = \Yii::$app->request->post(AdminHtml::ACTION_BUTTON_NAME, AdminHtml::ACTION_SAVE_AND_LEAVE);
if (isset($actions[$actionName])) {
return call_user_func($actions[$actionName]);
} else {
throw new BadRequestHttpException('Unknown action: ' . $actionName);
}
}
示例2: oAuthSuccess
public function oAuthSuccess($client)
{
// get user data from client
$userAttributes = $client->getUserAttributes();
$email = $userAttributes['emails'][0]['value'];
$player = Player::findByEmail($email);
if ($player == null) {
$player = new Player();
$player->email = $email;
if (isset($userAttributes['image']) && isset($userAttributes['image']['url'])) {
$photo = explode('?', $userAttributes['image']['url'])[0];
$player->photo = $photo;
}
if (isset($userAttributes['name'])) {
$player->first_name = $userAttributes['name']['givenName'];
$player->last_name = $userAttributes['name']['familyName'];
}
$player->generateAuthKey();
$player->generateAccessToken();
$player->save();
}
if (Yii::$app->user->login($player, 3600 * 24 * 30)) {
return $this->redirect(Url::previous());
}
}
示例3: actionDelete
/**
* Deletes an existing Employee model.
* If deletion is successful, the browser will be redirected to the 'index' page.
* @param integer $id
* @return mixed
*/
public function actionDelete($id)
{
$model = $this->findModel($id);
$model->setScenario('change_status');
$model->delete();
return $this->redirect(Url::previous());
}
示例4: actionIndex
public function actionIndex($lang = 'id')
{
Yii::$app->language = $lang;
$cookie = new \yii\web\Cookie(['name' => 'lang', 'value' => $lang]);
\Yii::$app->getResponse()->getCookies()->add($cookie);
return $this->redirect(Url::previous());
}
示例5: actionDelete
/**
* Deletes an existing Message model.
* If deletion is successful, the browser will be redirected to the 'index' page.
* @param integer $id
* @return mixed
*/
public function actionDelete($id)
{
$this->findModel($id)->delete();
Message::deleteAll(['id' => $id]);
Yii::$app->getSession()->setFlash('success', Yii::t('admin', 'Entry has been deleted successfully'));
return $this->redirect(Url::previous());
}
示例6: init
/**
* @inheritdoc
*/
public function init()
{
parent::init();
if (!isset($this->redirectUrl)) {
$this->redirectUrl = Url::previous();
}
}
示例7: actionIndex
public function actionIndex()
{
if (yii::$app->user->isGuest == true) {
return $this->render('index');
} else {
$this->redirect(Url::previous('safe_url'));
}
}
示例8: actionUpdate
/**
* Updates an existing Books model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id
* @return mixed
*/
public function actionUpdate($id)
{
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(Url::previous());
}
return $this->render('update', ['model' => $model]);
}
示例9: actionDelete
public function actionDelete($id)
{
$model = $this->findModel($id);
if (!Yii::$app->user->can('isOwner', ['model' => $model])) {
throw new ForbiddenHttpException('Access denied');
}
$model->delete();
return $this->redirect(Url::previous());
}
示例10: actionPrevious
/** 跳转回上一个记住的网页 */
public function actionPrevious()
{
$previous = Url::previous();
if ($previous) {
return $this->redirect($previous);
} else {
return $this->redirect(['user-aaa/index']);
}
}
示例11: actionDelete
public function actionDelete($id)
{
$this->getModule()->detachFile($id);
if (\Yii::$app->request->isAjax) {
return json_encode([]);
} else {
return $this->redirect(Url::previous());
}
}
示例12: actionUpdate
/**
* Updates an existing I18nMessage model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id
* @param string $language
* @return mixed
*/
public function actionUpdate($id, $language)
{
$model = $this->findModel($id, $language);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(Url::previous('i18n-messages-filter') ?: ['index']);
} else {
return $this->render('update', ['model' => $model]);
}
}
示例13: init
/**
* @throws InvalidConfigException
*/
public function init()
{
parent::init();
if (!$this->redirectUrl) {
$this->redirectUrl = Url::previous(self::URL_NAME_INDEX_ACTION);
}
if (!is_subclass_of($this->modelClass, BaseActiveRecord::className())) {
throw new InvalidConfigException("Property 'modelClass': given class extend '" . BaseActiveRecord::className() . "'");
}
}
示例14: actionUpdate
/**
* Updates an existing Book model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id
* @return mixed
*/
public function actionUpdate($id)
{
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
$file = UploadedFile::getInstance($model, 'preview');
if ($model->upload($file) && $model->save()) {
return $this->redirect(Url::previous());
}
}
return $this->render('update', ['model' => $model, 'authors' => Author::find()->all()]);
}
示例15: init
/**
* @inheritdoc
* @throws InvalidConfigException
*/
public function init()
{
parent::init();
if (empty($this->gridId) || empty($this->gridManager)) {
throw new InvalidConfigException('Property "gridId" and "gridManager" must be specified.');
}
$this->gridManager = Instance::ensure($this->gridManager, 'bupy7\\grid\\interfaces\\ManagerInterface');
if (!isset($this->redirectUrl)) {
$this->redirectUrl = Url::previous();
}
}