


Summary of commonly used variables in yii templates_PHP tutorial
A summary of commonly used variables in yii templates
A summary of some commonly used variables in yii templates.
There is such a URL: http://www.phpernote.com/demos/helloworld/index.php/xxx/xxx
The values obtained through the following methods correspond to:
Home page address except domain name
echo Yii::app()->user->returnUrl; // '/demos/helloworld/index.php'
Current page url
echo Yii::app()->request->url; // '/demos/helloworld/index.php/xxx/xxx'
Current domain name
echo Yii::app()->request->hostInfo; // 'http://www.phpernote.com/'
Root URL
echo Yii::app()->request->baseUrl; // '/demos/helloworld'
Root directory address except domain name
echo Yii::app()->homeUrl; // '/demos/helloworld/index.php'
Create url address
echo Yii::app()->createUrl('Site'); // /demos/helloworld/index.php?r=Site
URL except domain name
Yii::app()->request->getUrl();
Jump to the previous page url $this->redirect(Yii::app()->request->urlReferrer);
Jump to the current page url Yii::app()->request->redirect(Yii::app()->user->returnUrl);
Create url address Yii::app()->createUrl('/',array('param1'=>'val')); // /demos/helloworld/index.php
Render view (layout) $this->render('view', array('attribute1'=>'value1','attribute2'=>'value2'));
Jump page $this->redirect(array('route','attribute1'=>'value1','attribute2'=>'value2'));
Create widget $this->beginWidget(string $className, array $properties=array ( ))
$this->endWidget();
Partial rendering renderPartial('view', array('attribute1'=>'value1','attribute2'=>'value2'));
Call jquery in the YII framework: Yii::app()->clientScript->registerCoreScript('jquery');
js of framework/web/js/source, the files called by registerCoreScriptkey can be viewed in the framework/web/js/packages.php list
Method to get the ID of the current controller in the view: Yii::app()->getController()->id;
Get the ID method of the current action in the view: Yii::app()->getController()->getAction()->id;
yii gets the ip address: Yii::app()->request->userHostAddress;
yii determines the submission method: Yii::app()->request->isPostRequest
Get the current domain name: Yii::app()->request->hostInfo
Get the physical path of the protected directory: YII::app()->basePath;
Get the url of the previous page to return: Yii::app()->request->urlReferrer;
Get the current url: Yii::app()->request->url;
Get the current home url: Yii::app()->homeUrl
Get the current return url: Yii::app()->user->returnUrl
Project path: dirname(Yii::app()->BasePath)
1: Namespace constants defined by Yii framework
system: points to the Yii framework directory; Yiiframework
zii: points to the zii library directory; Yiiframeworkzii
application: Points to the application base directory; protected
webroot: points to the directory containing the entry script file; .
ext : points to the directory containing all third-party extensions; protectedextensions
Usage: Yii::getPathOfAlias('webroot')
Two: Get the current complete path
Yii::getFrameworkPath() :YII framework path
Three: Insert meta information
Yii::app()->clientScript->registerMetaTag('keywords','keyword');
Yii::app()->clientScript->registerMetaTag('description','Some description');
Yii::app()->clientScript->registerMetaTag('author','author');
Example:
is expressed as: Yii::app()->clientScript->registerLinkTag('alternate','application/xml',$this->createUrl('/feed'));
Add CSS files or JavaScript files in the controller
Yii::app()->clientScript->registerCssFile(Yii::app()->baseUrl.'/css/my.css');
Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl.'/css/my.js');
Method to get the ID of the current controller in the view
Yii::app()->getController()->id;
Get the ID of the current action in the view
Yii::app()->getController()->getAction()->id;
Yii gets ip address
Yii::app()->request->userHostAddress;
Yii determines the submission method
Yii::app()->request->isPostRequest
Get the physical path of the protected directory Yii::app()->basePath;
Project path dirname(Yii::app()->basePath)
Articles you may be interested in
- Yii framework module development analysis
- Yii rules common verification rules memo
- Understanding of Yii framework Yiiapp()
- Summary of commonly used system variables in Thinkphp templates
- Summary of common methods of Yii CDbCriteria
- A summary of how to use database transactions in Yii
- Using php functions in smarty templates and how to use multiple functions for one variable in smarty templates
- A summary of common path methods in Yii

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











The reason for the error is NameResolutionError(self.host,self,e)frome, which is an exception type in the urllib3 library. The reason for this error is that DNS resolution failed, that is, the host name or IP address attempted to be resolved cannot be found. This may be caused by the entered URL address being incorrect or the DNS server being temporarily unavailable. How to solve this error There may be several ways to solve this error: Check whether the entered URL address is correct and make sure it is accessible Make sure the DNS server is available, you can try using the "ping" command on the command line to test whether the DNS server is available Try accessing the website using the IP address instead of the hostname if behind a proxy

Differences: 1. Different definitions, url is a uniform resource locator, and html is a hypertext markup language; 2. There can be many urls in an html, but only one html page can exist in a url; 3. html refers to is a web page, and url refers to the website address.

Summary of the system() function under Linux In the Linux system, the system() function is a very commonly used function, which can be used to execute command line commands. This article will introduce the system() function in detail and provide some specific code examples. 1. Basic usage of the system() function. The declaration of the system() function is as follows: intsystem(constchar*command); where the command parameter is a character.

How to solve the problem of jQueryAJAX error 403? When developing web applications, jQuery is often used to send asynchronous requests. However, sometimes you may encounter error code 403 when using jQueryAJAX, indicating that access is forbidden by the server. This is usually caused by server-side security settings, but there are ways to work around it. This article will introduce how to solve the problem of jQueryAJAX error 403 and provide specific code examples. 1. to make

Explore the Canvas framework: To understand what are the commonly used Canvas frameworks, specific code examples are required. Introduction: Canvas is a drawing API provided in HTML5, through which we can achieve rich graphics and animation effects. In order to improve the efficiency and convenience of drawing, many developers have developed different Canvas frameworks. This article will introduce some commonly used Canvas frameworks and provide specific code examples to help readers gain a deeper understanding of how to use these frameworks. 1. EaselJS framework Ea

Using Ajax to obtain variables from PHP methods is a common scenario in web development. Through Ajax, the page can be dynamically obtained without refreshing the data. In this article, we will introduce how to use Ajax to get variables from PHP methods, and provide specific code examples. First, we need to write a PHP file to handle the Ajax request and return the required variables. Here is sample code for a simple PHP file getData.php:

Python is widely used in a wide range of fields with its simple and easy-to-read syntax. It is crucial to master the basic structure of Python syntax, both to improve programming efficiency and to gain a deep understanding of how the code works. To this end, this article provides a comprehensive mind map detailing various aspects of Python syntax. Variables and Data Types Variables are containers used to store data in Python. The mind map shows common Python data types, including integers, floating point numbers, strings, Boolean values, and lists. Each data type has its own characteristics and operation methods. Operators Operators are used to perform various operations on data types. The mind map covers the different operator types in Python, such as arithmetic operators, ratio

Instance variables in Java refer to variables defined in the class, not in the method or constructor. Instance variables are also called member variables. Each instance of a class has its own copy of the instance variable. Instance variables are initialized during object creation, and their state is saved and maintained throughout the object's lifetime. Instance variable definitions are usually placed at the top of the class and can be declared with any access modifier, which can be public, private, protected, or the default access modifier. It depends on what we want this to be
