本文整理汇总了PHP中yii\helpers\Url::to方法的典型用法代码示例。如果您正苦于以下问题:PHP Url::to方法的具体用法?PHP Url::to怎么用?PHP Url::to使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\helpers\Url
的用法示例。
在下文中一共展示了Url::to方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
public function run()
{
$request = Yii::$app->request;
$user = Yii::createObject($this->modelClass, ['scenario' => $this->scenario]);
$profile = Yii::createObject($this->profileClass);
$roles = [];
if ($this->roleArray !== null) {
$roles = call_user_func($this->roleArray, $this);
}
$roleArray = ArrayHelper::map($roles, 'name', 'description');
$statusArray = [];
if ($this->statusArray !== null) {
$statusArray = call_user_func($this->statusArray, $this);
}
if ($user->load($request->post()) && $profile->load($request->post())) {
if ($user->validate() && $profile->validate()) {
$user->populateRelation('profile', $profile);
if ($user->save(false)) {
$this->trigger('success', new Event(['data' => $user]));
return $this->controller->redirect(Url::to([$this->updateRoute, 'id' => $user->id]));
} else {
$this->trigger('success', new Event(['data' => Module::t('admin', 'Failed create user')]));
return $this->controller->refresh();
}
} elseif ($request->isAjax) {
Yii::$app->response->format = Response::FORMAT_JSON;
return array_merge(ActiveForm::validate($user), ActiveForm::validate($profile));
}
}
return $this->render(compact(['user', 'profile', 'roleArray', 'statusArray']));
}
示例2: actionUpload_product
public function actionUpload_product()
{
if (Yii::$app->request->isAjax) {
$model = new ProductCategory();
$Product = new Product();
$ProductImageRel = new ProductImageRel();
$ProductCategoryRel = new ProductCategoryRel();
$model_cat_title = UploadedFile::getInstance($model, 'cat_title');
$time = time();
$model_cat_title->saveAs('product_uploads/' . $time . $model_cat_title->baseName . '.' . $model_cat_title->extension);
if ($model_cat_title) {
$response = [];
$Product->title = $_POST['title'];
$Product->desc = $_POST['desc'];
$Product->status = 1;
if ($Product->save()) {
$ProductCategoryRel->category_id = $_POST['id'];
$ProductCategoryRel->product_id = $Product->id;
$ProductImageRel->product_id = $Product->id;
$ProductImageRel->image = $time . $model_cat_title->baseName . '.' . $model_cat_title->extension;
if ($ProductCategoryRel->save() && $ProductImageRel->save()) {
$response['files'][] = ['name' => $time . $model_cat_title->name, 'type' => $model_cat_title->type, 'size' => $model_cat_title->size, 'url' => Url::base() . '/product_uploads/' . $time . $model_cat_title->baseName . '.' . $model_cat_title->extension, 'deleteUrl' => Url::to(['delete_uploaded_file', 'file' => $model_cat_title->baseName . '.' . $model_cat_title->extension]), 'deleteType' => 'DELETE'];
$response['base'] = $time . $model_cat_title->baseName;
$response['view'] = $this->renderAjax('uploaded_product', ['url' => Url::base() . '/product_uploads/' . $time . $model_cat_title->baseName . '.' . $model_cat_title->extension, 'basename' => $time . $model_cat_title->baseName, 'id' => $ProductImageRel->id, 'model' => $Product]);
}
} else {
$response['errors'] = $product->getErrors();
}
return json_encode($response);
}
}
}
示例3: actionRss
public function actionRss()
{
/** @var News[] $news */
$news = News::find()->where(['status' => News::STATUS_PUBLIC])->orderBy('id DESC')->limit(50)->all();
$feed = new Feed();
$feed->title = 'YiiFeed';
$feed->link = Url::to('');
$feed->selfLink = Url::to(['news/rss'], true);
$feed->description = 'Yii news';
$feed->language = 'en';
$feed->setWebMaster('sam@rmcreative.ru', 'Alexander Makarov');
$feed->setManagingEditor('sam@rmcreative.ru', 'Alexander Makarov');
foreach ($news as $post) {
$item = new Item();
$item->title = $post->title;
$item->link = Url::to(['news/view', 'id' => $post->id], true);
$item->guid = Url::to(['news/view', 'id' => $post->id], true);
$item->description = HtmlPurifier::process(Markdown::process($post->text));
if (!empty($post->link)) {
$item->description .= Html::a(Html::encode($post->link), $post->link);
}
$item->pubDate = $post->created_at;
$item->setAuthor('noreply@yiifeed.com', 'YiiFeed');
$feed->addItem($item);
}
$feed->render();
}
示例4: init
/**
* @inheritdoc
*/
public function init()
{
parent::init();
// set titles
$this->setCreateTitle(Yii::t('kalibao', 'create_title'));
$this->setUpdateTitle(Yii::t('kalibao', 'update_title'));
// models
$models = $this->getModels();
// language
$language = $this->getLanguage();
// get drop down list methods
$dropDownList = $this->getDropDownList();
// upload config
$uploadConfig['main'] = $this->uploadConfig[(new \ReflectionClass($models['main']))->getName()];
// set items
$items = [];
if (!$models['main']->isNewRecord) {
$items[] = new SimpleValueField(['model' => $models['main'], 'attribute' => 'id', 'value' => $models['main']->id]);
}
$items[] = new InputField(['model' => $models['main'], 'attribute' => 'file', 'type' => 'activeFileInput', 'options' => ['maxlength' => true, 'class' => 'input-advanced-uploader', 'placeholder' => $models['main']->getAttributeLabel('file'), 'data-type-uploader' => $uploadConfig['main']['file']['type'], 'data-file-url' => $models['main']->file != '' ? $uploadConfig['main']['file']['baseUrl'] . '/' . $models['main']->file : '']]);
$items[] = new InputField(['model' => $models['main'], 'attribute' => 'media_type_id', 'type' => 'activeHiddenInput', 'options' => ['class' => 'form-control input-sm input-ajax-select', 'data-action' => Url::to(['advanced-drop-down-list', 'id' => 'media_type_i18n.title']), 'data-allow-clear' => 1, 'data-placeholder' => Yii::t('kalibao', 'input_select'), 'data-text' => !empty($models['main']->media_type_id) ? MediaTypeI18n::findOne(['media_type_id' => $models['main']->media_type_id, 'i18n_id' => $language])->title : '']]);
$items[] = new InputField(['model' => $models['i18n'], 'attribute' => 'title', 'type' => 'activeTextInput', 'options' => ['class' => 'form-control input-sm', 'maxlength' => true, 'placeholder' => $models['i18n']->getAttributeLabel('title')]]);
if (!$models['main']->isNewRecord) {
$items[] = new SimpleValueField(['model' => $models['main'], 'attribute' => 'created_at', 'value' => Yii::$app->formatter->asDatetime($models['main']->created_at, I18N::getDateFormat())]);
}
if (!$models['main']->isNewRecord) {
$items[] = new SimpleValueField(['model' => $models['main'], 'attribute' => 'updated_at', 'value' => Yii::$app->formatter->asDatetime($models['main']->updated_at, I18N::getDateFormat())]);
}
$this->setItems($items);
}
示例5: actionAdd
public function actionAdd()
{
$requestId = yii::$app->request->get('id');
$id = isset($requestId) ? (int) $requestId : 0;
$item = $this->GetModel()->GetItem($id);
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);
}
}
$interace = $this->MakeInterface($item);
$this->headerPage = "Новый тип страницы";
return $this->render('add', ["interface" => $interace, "id" => $id]);
}
示例6: init
public function init()
{
$url = is_array($this->route) ? Url::to($this->route) : Url::to([$this->route, 'term' => 'QUERY']);
$this->dataset = [['remote' => ['url' => $url, 'wildcard' => 'QUERY'], 'templates' => ['empty' => Html::tag('span', Yii::t('app', 'Hit enter to search'), ['class' => 'empty-search']), 'suggestion' => new JsExpression("Handlebars.compile('{$this->template}')")]]];
$this->pluginOptions = ['hint' => false];
parent::init();
}
示例7: run
public function run()
{
//Если данные по доставке закешированы просто рисуем их иначе делаем ajax запрос, чтобы заполнился кеш
if (\Yii::$app->v3toysSettings->isCurrentShippingCache) {
return $this->render($this->viewFile);
} else {
$js = \yii\helpers\Json::encode(['backend' => \yii\helpers\Url::to('/v3toys/cart/get-current-shipping')]);
$this->view->registerJs(<<<JS
(function(sx, \$, _)
{
sx.classes.GetShipping = sx.classes.Component.extend({
_onDomReady: function()
{
var self = this;
_.delay(function()
{
sx.ajax.preparePostQuery(self.get('backend')).execute();
}, 500);
}
});
new sx.classes.GetShipping({$js});
})(sx, sx.\$, sx._);
JS
);
}
}
示例8: up
public function up()
{
mb_internal_encoding("UTF-8");
$tableOptions = $this->db->driverName === 'mysql' ? 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB' : null;
$this->createTable('{{%wysiwyg}}', ['id' => Schema::primaryKey(), 'name' => Schema::string()->notNull(), 'class_name' => Schema::string()->notNull(), 'params' => Schema::text(), 'configuration_model' => Schema::string()], $tableOptions);
$this->insert('{{%wysiwyg}}', ['name' => 'Imperavi', 'class_name' => 'vova07\\imperavi\\Widget', 'params' => Json::encode(['settings' => ['replaceDivs' => false, 'minHeight' => 200, 'paragraphize' => false, 'pastePlainText' => true, 'buttonSource' => true, 'imageManagerJson' => Url::to(['/backend/dashboard/imperavi-images-get']), 'plugins' => ['table', 'fontsize', 'fontfamily', 'fontcolor', 'video', 'imagemanager'], 'replaceStyles' => [], 'replaceTags' => [], 'deniedTags' => [], 'removeEmpty' => [], 'imageUpload' => Url::to(['/backend/dashboard/imperavi-image-upload'])]]), 'configuration_model' => 'app\\modules\\core\\models\\WysiwygConfiguration\\Imperavi']);
}
示例9: actionProductpic
/**
* 上传商品图片
*/
public function actionProductpic()
{
$user_id = \Yii::$app->user->getId();
$p_params = Yii::$app->request->get();
$product = Product::findOne($p_params['id']);
if (!$product) {
throw new NotFoundHttpException(Yii::t('app', 'Page not found'));
}
$picture = new UploadForm();
$picture->file = UploadedFile::getInstance($product, 'product_s_img');
if ($picture->file !== null && $picture->validate()) {
Yii::$app->response->getHeaders()->set('Vary', 'Accept');
Yii::$app->response->format = Response::FORMAT_JSON;
$response = [];
if ($picture->productSave()) {
$response['files'][] = ['name' => $picture->file->name, 'type' => $picture->file->type, 'size' => $picture->file->size, 'url' => '/' . $picture->getImageUrl(), 'thumbnailUrl' => '/' . $picture->getOImageUrl(), 'deleteUrl' => Url::to(['/uploadfile/deletepropic', 'id' => $picture->getID()]), 'deleteType' => 'POST'];
} else {
$response[] = ['error' => Yii::t('app', '上传错误')];
}
@unlink($picture->file->tempName);
} else {
if ($picture->hasErrors()) {
$response[] = ['error' => '上传错误'];
} else {
throw new HttpException(500, Yii::t('app', '上传错误'));
}
}
return $response;
}
示例10: makeUrl
/**
* Returns file url for requested size.
* @param $path - path to file from DB
* @param string $size - image size
* @param bool|false $absoluteUrl
* @return string
*/
public static function makeUrl($path, $size = 'original', $absoluteUrl = false)
{
if (preg_match('/^(http:\\/\\/|https:\\/\\/|\\/\\/).*/', $path)) {
return $path;
}
return Url::to(self::normalizePath(self::$uploadDir . $size . $path, '/'), $absoluteUrl);
}
示例11: run
function run()
{
foreach ($this->data as $n => $v) {
if (isset($this->{$n})) {
$this->{$n} = $v;
}
}
$this->view->registerCssFile('http://code.ionicframework.com/ionicons/1.5.2/css/ionicons.min.css');
$link = $this->link;
if (is_array($link)) {
$link = Url::to($link);
}
if ($this->link_text === null) {
$this->link_text = \Yii::t('app', 'More info');
}
$html = "<!-- small box -->\n";
$html .= "<div class=\"col-lg-3 col-xs-6\">\n";
$html .= " <div class=\"small-box {$this->color}\">\n";
$html .= " <div class=\"inner\">";
$html .= Html::tag('h3', $this->count . Html::tag('sup', $this->count_type, ['style' => "font-size: 20px"]));
$html .= Html::tag('p', $this->text);
$html .= "</div>\n";
$html .= " <div class=\"icon\">";
$html .= Html::tag('i', '', ['class' => 'ion ' . $this->icon]);
$html .= "</div>\n";
$html .= " ";
$html .= Html::a($this->link_text . " <i class=\"fa fa-arrow-circle-right\"></i>", $link, ['class' => 'small-box-footer']);
$html .= " </div>";
$html .= "</div>";
return $html;
}
示例12: actionAdd
public function actionAdd()
{
$id = !empty(yii::$app->request->get('id')) ? yii::$app->request->get('id') : 0;
$this->titlePage = "Добавление элемента на страницу блог";
$this->headerPage = "Новый элемент";
$item = $this->GetModel()->GetItem($id);
if ($item) {
$this->titlePage = $item["name"];
$this->headerPage = "Редактирование элемента - " . $item["name"];
}
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_properties = new ModelProperties();
$model = $this->GetModel();
$model->attributes = $fields["main"];
if ($model->validate()) {
$insert_id = $model->Add($id, $fields["main"]);
$model_properties->Add($insert_id, $fields['properties']);
$this->redirect(Url::to(["/{$pathInfo}", "id" => $insert_id]));
} else {
$errors = $model->errors;
app::PrintPre($errors);
}
}
$interface = $this->MakeInterface($item, 21);
return $this->render('add', array("interface" => $interface, "data" => $item));
}
示例13: actionCreate
public function actionCreate()
{
$productOrder = $this->getModel(Yii::$app->request->post('orderId'));
$chargeForm = new ChargeForm();
$chargeForm->order_no = $productOrder->id;
$chargeForm->amount = $productOrder->payAmount;
/**
* @see Channel
*/
$chargeForm->channel = Channel::ALIPAY_PC_DIRECT;
$chargeForm->currency = 'cny';
$chargeForm->client_ip = Yii::$app->getRequest()->userIP;
$chargeForm->subject = sprintf("为订单ID为#%s的订单付款。", $productOrder->id);
$chargeForm->body = sprintf('订单总价为 %s, 联系方式为 %s, 联系地址为 %s', $productOrder->total_price, $productOrder->contact, $productOrder->address);
$chargeForm->extra = ['success_url' => Url::to(['success-sync-callback'], true)];
if ($response = $chargeForm->create()) {
$productOrder->out_order_no = $response->order_no;
$productOrder->charge_id = $response->id;
if ($productOrder->save()) {
return $response->__toArray(true);
}
} elseif ($chargeForm->hasErrors()) {
return $chargeForm->getErrors();
}
throw new ServerErrorHttpException();
}
示例14: actionUpload
public function actionUpload($model, $primaryKey)
{
$results = [];
$modelImage = new Image();
$modelImage->model = $model;
$modelImage->primaryKey = $primaryKey;
$filePath = $modelImage->getFilePath();
if (Yii::$app->request->isPost) {
$modelImage->file = UploadedFile::getInstance($modelImage, 'file');
if ($modelImage->file && $modelImage->validate()) {
$filename = $modelImage->file->name;
$modelImage->src = $filename;
$modelImage->position = $modelImage->nextPosition;
$modelImage->save();
$image = \Yii::$app->image->load($modelImage->file->tempName);
$image->resize(2592, 1728, \yii\image\drivers\Image::AUTO);
if ($image->save($filePath . '/' . $filename)) {
$imagePath = $filePath . '/' . $filename;
$result = ['name' => $filename, 'size' => filesize($filePath . '/' . $filename), 'url' => $imagePath, 'thumbnailUrl' => $modelImage->resize('100x100'), 'deleteUrl' => Url::to(['/core/image/delete', 'id' => $modelImage->id]), 'deleteType' => "DELETE"];
$results[] = $result;
}
} else {
$results[] = (object) [$modelImage->file->name => false, 'error' => strip_tags(Html::error($modelImage, 'file')), 'extension' => $modelImage->file->extension, 'type' => $modelImage->file->type];
}
}
echo json_encode((object) ['files' => $results]);
}
示例15: actionIndex
public function actionIndex()
{
$admin = Administrator::find()->all();
$this->var['breadcumb'] = [Url::to(["administrator/manager"]) => "Quản lý cấp quyền quản trị"];
$this->var['table_name'] = 'Quản lý cấp quyền quản trị';
return $this->render('auth', ['data' => $admin]);
}