本文整理汇总了PHP中Url::to方法的典型用法代码示例。如果您正苦于以下问题:PHP Url::to方法的具体用法?PHP Url::to怎么用?PHP Url::to使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Url
的用法示例。
在下文中一共展示了Url::to方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: notify
public static function notify($thread)
{
if (is_numeric($thread) && $thread > 0) {
$email = Content::find()->where(['name' => 'email-sub'])->one();
if ($email) {
$topic = $email->topic;
$content = $email->content;
} else {
$topic = 'New post in subscribed thread at {forum}';
$content = '<p>There has been new post added in the thread you are subscribing. Click the following link to read the thread.</p><p>{link}</p><p>See you soon!<br />{forum}</p>';
}
$forum = Config::getInstance()->get('name');
$subs = static::find()->where(['thread_id' => (int) $thread, 'post_seen' => static::POST_SEEN]);
foreach ($subs->each() as $sub) {
$sub->post_seen = static::POST_NEW;
if ($sub->save()) {
if (Email::queue($sub->user->email, str_replace('{forum}', $forum, $topic), str_replace('{forum}', $forum, str_replace('{link}', Html::a(Url::to(['default/last', 'id' => $sub->thread_id], true), Url::to(['default/last', 'id' => $sub->thread_id], true)), $content)), !empty($sub->user_id) ? $sub->user_id : null)) {
Log::info('Subscription notice link queued', !empty($sub->user_id) ? $sub->user_id : '', __METHOD__);
} else {
Log::error('Error while queuing subscription notice link', !empty($sub->user_id) ? $sub->user_id : '', __METHOD__);
}
}
}
}
}
示例2: actionAdd
public function actionAdd()
{
$id = !empty(yii::$app->request->get('id')) ? yii::$app->request->get('id') : 0;
$item = $this->GetModel()->GetItem($id);
if ($item) {
$this->headerPage = "Редактировать слайдер " . $item["name"];
} else {
$this->headerPage = "Новый слайдер";
}
if (yii::$app->request->isPost) {
$pathInfo = Yii::$app->request->pathInfo;
$fields = Yii::$app->request->post();
if (isset($fields["main"]["id"])) {
$id = $fields["main"]["id"];
} else {
$id = Yii::$app->request->get('id') ? (int) Yii::$app->request->get('id') : 0;
}
$model = $this->GetModel();
$model->attributes = $fields["main"];
if ($model->validate()) {
$insert_id = $model->Add($id, $fields["main"]);
$this->redirect(Url::to(["/{$pathInfo}", "id" => $insert_id]));
} else {
$errors = $model->errors;
app::PrintPre($errors);
}
}
$interface = $this->MakeInterface($item);
return $this->render('add', ['interface' => $interface, 'data' => $item]);
}
示例3: actionSaveComment
public function actionSaveComment()
{
if (!isset($_POST['article_id'])) {
return $this->redirect('/article');
}
Comment::saveComment($_POST, true);
$this->redirect(Url::to('/article/show/' . $_POST['article_id']));
}
示例4: getUrl
/**
* Zwraca urla danego obiektu
* @param integer $id
* @return string
*/
public function getUrl($id, $model)
{
$object = $model::find((int) $id);
if (isset($object->url)) {
$url = $object->url;
}
return \Url::to($url);
}
示例5: getUserDirectory
/**
* @param $user_id
* @return mixed
*/
private function getUserDirectory($user_id)
{
$uploads = Yii::$app->getModule('user')->uploads;
$path = str_replace('\\', '/', Url::to('@webroot') . DIRECTORY_SEPARATOR . $uploads . DIRECTORY_SEPARATOR . $user_id);
if (!file_exists($path)) {
mkdir($path, 0700, true);
}
return $path;
}
示例6: actionPing
public function actionPing($src)
{
$filename = basename($src);
$filepath = Url::to(ImgController::PING_IMG_DIR) . $filename;
if (!file_exists($filepath)) {
ImageHelper::createPingImg($src);
}
$path = Url::to(['/.resource/' . $filename], true);
$this->renderJsonpForJquery(['src' => $path]);
\Yii::$app->end();
}
示例7: actionSaveComment
public function actionSaveComment()
{
if (!isset($_POST['article_id'])) {
return $this->redirect('/article');
}
$comment = new Comment();
$comment->author_id = $_POST['author_id'];
$comment->article_id = $_POST['article_id'];
$comment->text = $_POST['text'];
$comment->save();
$this->redirect(Url::to('/article/show-article', ['id' => $_POST['article_id']]));
}
示例8: getDefaultAvatar
/**
* @return bool|mixed
*/
private function getDefaultAvatar()
{
$defaultPath = Url::to('@webroot') . DIRECTORY_SEPARATOR . $this->uploads . DIRECTORY_SEPARATOR . 'default';
$dataFile = Url::to('@app') . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . 'user' . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . $this->uploads . DIRECTORY_SEPARATOR . 'default' . DIRECTORY_SEPARATOR . $this->defaultAvatar;
$newFile = $defaultPath . DIRECTORY_SEPARATOR . $this->defaultAvatar;
if (!file_exists($defaultPath)) {
mkdir($defaultPath, 0700, true);
if (!copy($dataFile, $newFile)) {
return false;
}
}
$urlDefaultAvatar = str_replace('\\', '/', Url::to(DIRECTORY_SEPARATOR . $this->uploads . DIRECTORY_SEPARATOR . 'default' . DIRECTORY_SEPARATOR . $this->defaultAvatar));
return $urlDefaultAvatar;
}
示例9: jsFile
/**
* Generates a script tag that refers to an external JavaScript file.
* @param string $url the URL of the external JavaScript file. This parameter will be processed by [[\yii\helpers\Url::to()]].
* @param array $options the tag options in terms of name-value pairs. These will be rendered as
* the attributes of the resulting tag. The values will be HTML-encoded using [[encode()]].
* If a value is null, the corresponding attribute will not be rendered.
* See [[renderTagAttributes()]] for details on how attributes are being rendered.
* @return string the generated script tag
* @see \yii\helpers\Url::to()
*/
public static function jsFile($url, $options = [])
{
$options['src'] = Url::to($url);
if (!empty($options['conditions'])) {
foreach ($options['conditions'] as $file => $condition) {
if (strpos($url, $file) !== false) {
unset($options['conditions']);
return static::conditionalComment(static::tag('script', '', $options), $condition);
}
}
}
unset($options['conditions']);
return static::tag('script', '', $options);
}
示例10: get
static function get($img, $w = "", $h = "", $crop = true, $params = array())
{
$fullPath = public_path() . '/' . $img;
if (!File::exists($fullPath)) {
return false;
}
$format = '';
$width = '';
$htmlWidth = '';
$height = '';
$htmlHeight = '';
$filter = "";
$method = '';
$lazyParams = '';
$ext = File::extension($fullPath);
if ($ext == 'png') {
$firstBytes = @file_get_contents($fullPath, false, null, 25, 1);
if (ord($firstBytes) & 4) {
$format = "f=png";
//for transparent pngs
}
}
if ($w) {
$width = 'w=' . $w;
$htmlWidth = 'width="' . $w . '"';
}
if ($h) {
$height = 'h=' . $h;
$htmlHeight = 'height="' . $h . '"';
}
if (count($params) > 0) {
$filter = implode('&', $params);
//eg: fltr[]=gray
}
if ($w != "" && $h != "") {
if ($crop) {
$method = 'zc=1';
} else {
$method = 'far=1&bg=FFFFFF';
}
}
$image = 'src=' . $img;
$optionsSlices = array($method, $width, $height, $filter, $image, $format);
$options = implode('&', array_filter($optionsSlices));
$src = Url::to('/phpthumb') . "?" . $options;
$htmlOptionsSlices = array($htmlWidth, $htmlHeight, $lazyParams);
$htmlOptions = implode(' ', array_filter($htmlOptionsSlices));
return '<img src="' . $src . '" ' . $htmlOptions . ' />';
}
示例11: redirect
public function redirect($url, $force = false, $statusCode = 302)
{
$params = Yii::$app->request->queryParams;
// Meta redirect
if (headers_sent() || ob_get_contents()) {
$url = !empty($params['_return_url']) ? $params['_return_url'] : $url;
$url = Url::to($url);
$this->ech(Html::tag('meta', '', ['http-equiv' => 'Refresh', 'content' => '1;URL=' . $url . '']));
$this->ech(Html::a(__('Continue'), $url));
}
if (!empty($params['_return_url']) && !$force) {
return Yii::$app->getResponse()->redirect($params['_return_url'], $statusCode);
}
return parent::redirect($url, $statusCode);
}
示例12: athenticateTwitter
public static function athenticateTwitter()
{
$return_url = Url::to('/backend/system/settings/update/radiantweb/problog/settings');
$pb_auth = DB::table('radiantweb_twitter_auth')->first();
$oauth_token = Session::get('oauth_token');
$oauth_token_secret = Session::get('oauth_token_secret');
/* Create TwitteroAuth object with app key/secret and token key/secret from default phase */
$connection = new TwitterOAuth($pb_auth->twitter_key, $pb_auth->twitter_secret, $oauth_token, $oauth_token_secret);
/* Request access tokens from twitter */
$access_token = $connection->getAccessToken($_REQUEST['oauth_verifier']);
$data = array('twitter_auth_token' => $access_token['oauth_token'], 'twitter_auth_secret' => $access_token['oauth_token_secret']);
DB::table('radiantweb_twitter_auth')->where('twitter_key', $pb_auth->twitter_key)->update($data);
header('Location: ' . $return_url);
//return Redirect::to($return_url);
}
示例13: open
/**
* TODO Comments.
*/
public function open($action = null, $method = 'post', $enctype = false, $attributes = array())
{
if (is_null($action)) {
$action = Url::toCurrent();
} else {
$action = Url::to($action);
}
$attr = '';
if ($attributes) {
foreach ($attributes as $k => $v) {
$attr .= sprintf(' %s="%s"', $k, $v);
}
}
$enctype = $enctype ? ' enctype="multipart/form-data"' : '';
return sprintf('<form method="%s" action="%s"%s%s>', $method, $action, $enctype, $attr);
}
示例14: onDoTweet
function onDoTweet()
{
$settings = ProblogSettingsModel::instance();
$blogPost = $settings->get('blogPost');
$pb_auth = DB::table('radiantweb_twitter_auth')->first();
$PB_AUTH_TOKEN = $pb_auth->twitter_auth_token;
$PB_AUTH_SECRET = $pb_auth->twitter_auth_secret;
$PB_APP_KEY = $pb_auth->twitter_key;
$PB_APP_SECRET = $pb_auth->twitter_secret;
if ($PB_AUTH_TOKEN) {
$connection = new TwitterOAuth($PB_APP_KEY, $PB_APP_SECRET, $PB_AUTH_TOKEN, $PB_AUTH_SECRET);
$url = Url::to('/') . '/' . $blogPost . '/' . $this->model->slug . '/';
$msg = str_replace('{{url}}', $url, $_REQUEST['message']);
$update_status = $connection->post('statuses/update', ['status' => $msg]);
}
}
示例15: authenticate
/**
* Tries to authenticate user via social network. If user has already used
* this network's account, he will be logged in. Otherwise, it will try
* to create new user account.
*
* @param ClientInterface $client
*/
public function authenticate(ClientInterface $client)
{
$account = $this->finder->findAccount()->byClient($client)->one();
if ($account === null) {
$account = Account::create($client);
}
if ($account->user instanceof User) {
if ($account->user->isBlocked) {
Yii::$app->session->setFlash('danger', Yii::t('user', 'Your account has been blocked.'));
$this->action->successUrl = Url::to(['/user/security/login']);
} else {
if ($account->user->esActivo) {
Yii::$app->user->login($account->user, $this->module->rememberFor);
$this->action->successUrl = Yii::$app->getUser()->getReturnUrl();
}
}
} else {
$this->action->successUrl = $account->getConnectUrl();
}
}