Common URL and rendering methods of yii

Source: Internet
Author: User
Tags get ip

Current page url Yii: app ()-> request-> url;
Jump to the url of the previous page $ this-> redirect (Yii: app ()-> request-> urlReferrer );
Root directory URL Yii: app ()-> baseUrl or Yii: app ()-> request-> baseUrl;
Custom URL $ this-> createUrl ('Post/read', array ('id' => 100) or Yii: app ()-> createUrl ();

Current Project: Yii: getPathOfAlias ('webroot ');

HOST: Yii: app ()-> request-> hostInfo http: // 127.0.0.1

Project homepage Yii: app ()-> homeUrl/blog/index. php

If the browser is relocated to the logon page and the logon succeeds, we will relocate the browser to the page that causes verification failure. How do we know this value? We can use the returnUrl attribute of the user part. Therefore, we can use the following to execute redirection:

Yii: app ()-> request-> redirect (Yii: app ()-> user-> returnUrl );

Rendering view $ this-> render ('view', array ('bubute1' => 'value1 ', 'bubute2' => 'value2 '));
Jump to the page $ this-> redirect (array ('route ', 'bubute1' => 'value1', 'bubute2' => 'value2 '));
Create a widget $ this-> beginWidget (string $ className, array $ properties = array ())
$ This-> endWidget ();
Partial rendering renderPartial ('view', array ('bubute1' => 'value1 ', 'bubute2' => 'value2 '));
This method differs from render () in that it does not apply a layout to the rendered result. It is thus mostly used in rendering a partial view, or an AJAX response.

Call jquery: YII: app ()-> clientScript-> registerCoreScript ('jquery ') in the Yii framework ');

Framework/web/js/source js. The file called by registerCoreScriptkey can be viewed in the framework/web/js/packages. php list.

 

In the view, obtain the current controller ID method: Yii: app ()-> getController ()-> id;

 

Obtain the ID of the current action in the view: Yii: app ()-> getController ()-> getAction ()-> id;

 

Yii: Yii: app ()-> request-> userHostAddress;

 

Yii judgment submission method: Yii: app ()-> request-> isPostRequest

 

Obtain the current domain name: Yii: app ()-> request-> hostInfo

 

Obtain the physical path of the proteced Directory: YII: app ()-> basePath;

 

Get the URL of the previous page to return: yii: APP ()-> request-> urlreferrer;

 

Obtain the current URL: yii: APP ()-> request-> URL;

 

Obtain the current home URL: yii: APP ()-> homeurl.

 

Get the current return URL: yii: APP ()-> User-> returnurl

 

Project path: dirname (yii: APP ()-> basepath)

I. namespace constants defined by yii framework
System: points to the yii framework directory; yii \ framework
Zii: pointing to the zii library directory; yii \ framework \ zii
Application: points to the basic application directory; protected \
Webroot: Point to includePortal scriptFile directory ;.\
Ext: points to the directory containing all third-party extensions; \ protected \ extensions

 

Usage: yii: getpathofalias ('webroot ')

II:

{Full URL}: Get the current complete path
Yii: getframeworkpath (): yii framework path

 

III:

Insert meta information

Yii: app ()-> clientScript-> register1_ag ('keyword', 'keyword '); Yii: app ()-> clientScript-> register1_ag ('description ', 'Some description'); Yii: app ()-> clientScript-> register1_ag ('author', 'author ');

Example:

<Link rel = "alternate" type = "application/rss + xml" href = "http://www.dreamdu.com/feed/"/>

Indicates:

Yii: app ()-> clientScript-> registerLinkTag ('alternet', 'application/rss + xml', $ this-> createUrl ('/feed '));

 

Add a CSS or JavaScript file to the Controller

Yii: APP ()-> clientscript-> registercssfile (yii: APP ()-> baseurl. '/CSS/my.css'); yii: APP ()-> clientscript-> registerscriptfile (yii: APP ()-> baseurl. '/CSS/My. js ');

 

Obtain the ID method of the current controller in view.

Yii: APP ()-> getcontroller ()-> ID;

 

 

Obtain the ID of the current action in the view:

Yii: APP ()-> getcontroller ()-> getaction ()-> ID;

 

Yii get IP Address

Yii: APP ()-> request-> userhostaddress;

 

Yii judgment submission method

Yii: APP ()-> request-> ispostrequest

 

Get the current domain name:

Yii: APP ()-> request-> hostinfo

 

 

Obtain the physical path of the proteced directory.

Yii: APP ()-> basepath;

 

 

Returns the url of the previous page.

Yii: APP ()-> request-> urlreferrer;

 

 

Get the current url

 

Yii: APP ()-> request-> URL;

 

 

Get the current home url

 

Yii: APP ()-> homeurl

 

Returns the current return url.

 

Yii: APP ()-> User-> returnurl

 

Project path

 

Dirname (yii: APP ()-> basepath)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.