本文整理汇总了PHP中yii\helpers\Url::home方法的典型用法代码示例。如果您正苦于以下问题:PHP Url::home方法的具体用法?PHP Url::home怎么用?PHP Url::home使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\helpers\Url
的用法示例。
在下文中一共展示了Url::home方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionAdd
public function actionAdd()
{
if (User::thisUser()->reputation < Event::MIN_REPUTATION_EVENT_CREATE) {
return Yii::$app->getResponse()->redirect(Url::home());
}
$event = new Event();
if ($event->load(Yii::$app->request->post())) {
$eventPost = Yii::$app->request->post('Event');
$event->country = $eventPost['country'];
$event->description = \yii\helpers\HtmlPurifier::process($event->description, []);
$event->user_id = Yii::$app->user->identity->getId();
$event->date = strtotime($eventPost['date']);
$event->like_count = 0;
$event->show_count = 0;
if ($event->save()) {
// Добавляем теги
$tagsArr = explode(',', Yii::$app->request->post('tags'));
$tags = array_shift($tagsArr);
$event->saveTags($tags);
// Добавляем картинки к записи
$imgs = Yii::$app->request->post('imgs');
if (!empty($imgs) && is_array($imgs)) {
$event->saveImgs($imgs);
} else {
$event->saveImgs([]);
}
$event->saveLocations(Yii::$app->request->post('location'));
return Yii::$app->getResponse()->redirect($event->getUrl());
}
}
Yii::$app->params['jsZoukVar']['tagsAll'] = Tags::getTags(Tags::TAG_GROUP_ALL);
return $this->render('add', ['event' => $event]);
}
示例2: init
/**
* Initializes the widget.
*/
public function init()
{
parent::init();
if ($this->baseUrl === null) {
$this->baseUrl = Url::home();
}
}
示例3: upload
public static function upload($value)
{
$document = new Documents();
foreach ($value as $item => $i) {
$document->{$item} = $i;
}
$document->created_at = time();
$document->updated_at = time();
$document->user = $value['user'];
$token = Util::generateRandomStringCode(20);
$document->token = $token;
// echo \yii\helpers\Url::home(true) . $value['original_url'];die;
$document->money_url = Util::makeOuoUrl(\yii\helpers\Url::home(true) . $value['original_url']);
//$value['user'] = 1; //for testing
$user = Users::findOne(['id' => $value['user']]);
if (!$user) {
return Util::arrayError('Error !');
}
if ($document->save()) {
$user->number_upload += 1;
$user->points += 3;
$user->save();
return Util::arraySuccess('Success', $document->id);
}
return Util::arrayError('Error !');
}
示例4: actionList
/**
* @param integer $id
* @return mixed
*/
public function actionList($id = 0)
{
if (Yii::$app->request->isAjax) {
if (!$id) {
echo '';
Yii::$app->end();
}
$tourFields = Tour::find()->with('tourFields')->where(['id' => $id])->one();
$booking = new Booking();
$bookingFields = new BookingFields();
$bookingColumns = $booking->getTableSchema()->columns;
$sort = Json::decode($tourFields->sort);
$data = array_merge_recursive($sort, $bookingColumns);
$addField = [];
if ($tourFields->tourFields) {
foreach ($tourFields->tourFields as $field) {
$addField['add_field_' . $field->id] = ['sort' => $field->sort, 'name' => $field->name, 'type' => $field->type, 'tour_id' => $field->tour_id];
}
}
$data = array_merge($data, $addField);
unset($data['id']);
unset($data['tour_id']);
$data = $booking->customMultiSort($data, 'sort');
echo $this->renderAjax('_list', ['booking' => $booking, 'bookingFields' => $bookingFields, 'data' => $data]);
Yii::$app->end();
}
return $this->redirect(Url::home());
}
示例5: actionLogin
public function actionLogin()
{
$this->layout = false;
if (!$this->user->isGuest) {
$this->redirect(Yii::$app->getHomeUrl());
}
$model = new LoginForm();
if ($this->isPost) {
$model->attributes = $this->request->post();
if ($model->login()) {
if (!$this->isAjax) {
$cookies = $this->request->cookies;
if (isset($cookies[$this->user->returnUrlParam])) {
$backUrl = $cookies[$this->user->returnUrlParam]->value;
Yii::$app->response->cookies->remove($this->user->returnUrlParam);
} else {
$backUrl = Url::home(true);
}
$this->redirect($backUrl);
}
}
}
if ($this->isAjax && $this->isPost) {
throw new UserError($model->getErrors());
} else {
return $this->render('login', ['model' => $model]);
}
}
示例6: generateFeed
/**
* @param ATOM|RSS2 $feed
* @return ATOM|RSS2
*/
protected function generateFeed($feed)
{
/* @var Post[] $posts */
$site_name = ArrayHelper::getValue(Yii::$app->params, 'site_name', Yii::$app->name);
$posts = Post::find()->where(['status' => Post::STATUS_PUBLISHED])->orderBy(['post_time' => SORT_DESC, 'update_time' => SORT_DESC])->limit(20)->all();
$feed->setTitle($site_name);
$feed->setLink(Url::home(true));
$feed->setSelfLink(Url::to(['feed/rss'], true));
$feed->setAtomLink(Url::to(['feed/atom'], true));
$feed->setDescription(ArrayHelper::getValue(Yii::$app->params, 'seo_description', '最新更新的文章'));
if ($posts) {
$feed->setDate($posts[0]->update_time);
} else {
$feed->setDate(time());
}
foreach ($posts as $post) {
$entry = $feed->createNewItem();
$entry->setTitle($post->title);
$entry->setLink($post->getUrl(true));
$entry->setDate(intval($post->post_time));
$entry->setDescription($post->excerpt);
$entry->setAuthor($post->author_name ? $post->author_name : $post->author->nickname);
$entry->setId($post->alias);
if ($feed instanceof ATOM) {
$entry->setContent($post->content);
}
$feed->addItem($entry);
}
return $feed;
}
示例7: actionAdd
public function actionAdd()
{
$user = User::thisUser();
if (Yii::$app->request->isPost) {
$img = new Img();
$img->user_id = $user->id;
if ($img->save()) {
$img->imgFile = UploadedFile::getInstance($img, 'imgFile');
if ($img->imgFile instanceof UploadedFile && $img->validate('imgFile')) {
$prefix = Yii::$app->params['prefix'];
if (empty($prefix)) {
$prefix = "no_prefix";
}
$dirName = 'user' . $user->id;
$path = '/' . $prefix . '/img/' . $dirName . '/';
$fileName = 'img_' . $user->id . '_' . $img->id . '.' . pathinfo($img->imgFile->name, PATHINFO_EXTENSION);
if (!empty($prefix)) {
$fileName = $prefix . '_' . $fileName;
}
/** @var YandexDiskComponent $yandexDisk */
$yandexDisk = Yii::$app->yandexDisk;
$yandexDisk->setClientInfoImgDefault();
// Тест папки $path на существование
$pathInfo = $yandexDisk->getProperty($path);
if (!$pathInfo) {
$pathInfoMusic = $yandexDisk->getProperty('/' . $prefix . '/');
if (!$pathInfoMusic) {
$yandexDisk->createDirectory('/' . $prefix . '/');
}
$pathInfoMusic = $yandexDisk->getProperty('/' . $prefix . '/img/');
if (!$pathInfoMusic) {
$yandexDisk->createDirectory('/' . $prefix . '/img/');
}
$yandexDisk->createDirectory($path);
}
$fileInfo = $yandexDisk->getProperty($path . $fileName);
if (!$fileInfo) {
// Такого файла еще нет
$uploadInfo = $yandexDisk->uploadFile($path, (array) $img->imgFile, $fileName);
}
$publishInfo = $yandexDisk->startPublishing($path . $fileName);
if (is_string($publishInfo) && !empty($publishInfo)) {
$img->url = $publishInfo;
$shortUrl = Yii::$app->google->getShortUrl('https://getfile.dokpub.com/yandex/get/' . $publishInfo);
if (!empty($shortUrl['id'])) {
$img->short_url = $shortUrl['id'];
}
}
$img->key = $yandexDisk->key;
$img->entity_key = $yandexDisk::THIS_ENTITY;
$img->save();
}
}
$result = ['id' => $img->id, 'short_url' => $img->short_url];
return json_encode($result);
}
$this->redirect(Url::home());
}
示例8: isAdmin
public function isAdmin()
{
$rHostInfo = Url::home(true);
if (!\Yii::$app->user->isGuest && strpos(\Yii::$app->request->absoluteUrl, $rHostInfo . 'admin') !== false) {
return true;
} else {
return false;
}
}
示例9: actionDelete
/**
* Deletes this Space
*/
public function actionDelete()
{
$this->ownerOnly();
$model = new DeleteForm();
if ($model->load(Yii::$app->request->post()) && $model->validate()) {
$this->getSpace()->delete();
return $this->redirect(Url::home());
}
return $this->render('delete', array('model' => $model, 'space' => $this->getSpace()));
}
示例10: getCallback
/**
* {@url to="/path" /}
* {@url /}
*
* @return callable
*/
public function getCallback()
{
return function ($chunk, $context, $bodies, $params) {
if ($params->to) {
$code = Url::to($params->to);
} else {
$code = Url::home();
}
return $chunk->write($code);
};
}
示例11: lightbox
public function lightbox($title, $source, $target, $align = "left", $size = "")
{
$target_url = Url::home(true) . "images/" . $target;
$image_url = Url::home(true) . "images/" . $source;
$image_path = \Yii::getAlias('@app/web/images/') . $source;
if (is_file($image_path)) {
$image_info = array_values(getimagesize($image_path));
list($width, $height, $type, $attr) = $image_info;
}
return "<a href=\"" . $target_url . "\"" . " data-lightbox=\"" . str_replace('.', '_', str_replace('/', '_', $target)) . "\"" . " data-title=\"" . $title . "\"" . " title=\"" . $title . "\" class=\"sb\"><span class=\"imagewrap\"><img src=\"" . $image_url . "\" alt=\"" . $title . "\" title=\"" . $title . "\" class=\"gallery th " . $align . " floated image\"" . (!isset($width) ? "" : " width=\"" . $width . "\" ") . (!isset($height) ? "" : " height=\"" . $height . "\" ") . "/></span></a>";
}
示例12: init
public function init()
{
$pages = Page::find()->selectNoText()->published()->all();
$this->_htmlStr = '<ul class="menu">';
$this->_htmlStr .= '<li role="presentation" ' . ($this->active('site', 'index', '') ? 'class="nav-current"' : '') . '>' . Html::a('首页', Url::home()) . '</li>';
if (!empty($pages)) {
foreach ($pages as $page) {
$this->_htmlStr .= '<li role="presentation" ' . ($this->active('site', 'page', $page->slug) ? 'class="nav-current"' : '') . '>' . Html::a($page->title, ['site/page', 'slug' => $page->slug, $this->options]) . '</li>';
}
}
$this->_htmlStr .= '</ul>';
}
示例13: actionFeedback
public function actionFeedback()
{
$model = new Feedback();
if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) {
Yii::$app->response->format = Response::FORMAT_JSON;
return ActiveForm::validate($model);
}
if ($model->load($_POST) && $model->validate()) {
$model->send();
Yii::$app->controller->redirect(Url::home());
}
}
示例14: run
/**
* Runs the action
*
* @return string result content
*/
public function run()
{
$this->controller->layout = $this->layout;
if (Yii::$app->auth0->sdk()->getUser()) {
if (Yii::$app->auth0->login()) {
Yii::$app->user->login(Yii::$app->auth0->localUser);
Yii::$app->tenant->login();
}
return $this->controller->redirect(isset($this->redirectUrl) ? $this->redirectUrl : Url::home());
}
return $this->controller->render($this->view);
}
示例15: actionUrl
public function actionUrl()
{
$urls = [];
$urls[] = Url::base();
$urls[] = Url::current();
$urls[] = Url::previous();
// use before Url::remember()
$urls[] = Url::home();
$urls[] = Url::to('/');
$urls[] = Url::to('/test');
$urls[] = Url::to(['book']);
return VarDumper::dumpAsString($urls, 10, true);
}