Table of Contents
YII路径的用法总结,YII路径用法总结
YII中怎使用model中的search
Yii登陆 我想用自己的view模板页面,但是又想复用yii自带的验证登陆controller
Home php教程 php手册 YII路径的用法总结,YII路径用法总结

YII路径的用法总结,YII路径用法总结

Jun 13, 2016 am 09:29 AM
yii path

YII路径的用法总结,YII路径用法总结

在yii中如果是 // 就会默认去调 protected/views/layouts,//代表绝对路径。这其实就是绝对和相对的关系 /代表相对路径,如module/user下的layout。使用单斜杠的话默认会先找当前已经激活的模块底下的view,若当前未有激活的模块则从系统根目录下开始找,双斜杠的话就直接从系统根下开始找

Yii framework已经定义的命名空间常量:

system: 指向Yii框架目录; YII\framework
zii: 指向zii library 目录; YII\framework\zii
application: 指向应用程序基本目录;  protected\
webroot: 指向包含里入口脚本文件的目录. 此别名自 1.0.3 版起生效. \
ext: 指向包含所有第三方扩展的目录, 从版本 1.0.8 可用;  \protected\extensions

Yii::getPathOfAlias('zii') 
Yii::import ('zii.*')  
Yii::setPathOfAlias('backend', $backend); 
'import' => array( 
'backend.models.*',  

Copy after login

应用的主目录是指包含所有安全系数比较高的PHP代码和数据的根目录。在默认情况下,这个目录一般是入口代码所在目录的一个目录: protected。这个路径可以通过在application configuration里设置 basePath来改变.

YII framework路径:

Yii::getFrameworkPath() 
{full URL}

Copy after login

http://localhost/yii_lab/index.php?r=lab/urlBoyLeeTest 

Copy after login

protected/venders目录:

Yii::import('application.venders.*');  
Copy after login

或在protected/config/main.php说明:

'import'=>array(  
    ......  
    'application.venders.*',  
  ), 

Copy after login

插入meta信息:

Yii::app()->clientScript->registerMetaTag('keywords','关键字'); 
Yii::app()->clientScript->registerMetaTag('description','一些描述'); 
Yii::app()->clientScript->registerMetaTag('author','作者'); 
<link rel="alternate" type="application/rss+xml" href="http://www.bkjia.com/" />
Yii::app()->clientScript->registerLinkTag('alternate','application/rss+xml',$this->createUrl('/feed')); 

Copy after login

在控制器添加CSS文件或JavaScript文件:

Yii::app()->clientScript->registerCssFile(Yii::app()->baseUrl.'/css/my.css'); 
Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl.'/css/my.js'); 
<&#63;php echo $this->module->assetsUrl; &#63;>/css/main.css 

Copy after login

调用YII框架中framework/web/js/source的js,其中registerCoreScript key调用的文件在framework/web/js/packages.php列表中可以查看:

Yii::app()->clientScript->registerCoreScript('jquery'); 

Copy after login

在view中得到当前controller的ID方法:

Yii::app()->getController()->id;  

Copy after login

在view中得到当前action的ID方法:

Yii::app()->getController()->getAction()->id;  

Copy after login

yii获取ip地址

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

Copy after login

yii判断提交方式

Yii::app()->request->isPostRequest  

Copy after login

得到当前域名:

Yii::app()->request->hostInfo 

Copy after login

得到proteced目录的物理路径

YII::app()->basePath; 

Copy after login

获得上一页的url以返回

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

Copy after login

得到当前url

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

Copy after login

得到当前home url

Yii::app()->homeUrl 

Copy after login

得到当前return url

Yii::app()->user->returnUrl 

Copy after login

项目路径

dirname(Yii::app()->BasePath) 

Copy after login

如果你自己有个目录下有些类或文件常用,可以在main.php的最上边定义一个路径别名,别名可以被翻译为其相应的路径。

Yii::getPathOfAlias('webroot')  

Copy after login

如果是多个可以在main.php中的array中加一个配置

'aliases'=>array( 
'local'=>'path/to/local/' 
), 
<&#63;php echo $this->getLayoutFile('main'); &#63;>
$this->redirect('index.php&#63;r=admin/manage');
{createUrl()}
echo $this->createUrl('urlBoyLeeTest'); 
//out => /yii_lab/index.php&#63;r=lab/urlBoyLeeTest 
$this->createUrl('post/read') // /index.php/post/read 
<&#63;php echo Yii::app()->request->baseUrl; &#63;>/css/screen.css 
Yii::app()->theme->baseUrl.'/images/FileName.gif'  
{createAbsoluteUrl()}
echo $this->createAbsoluteUrl('urlBoyLeeTest'); 
//out => http://localhost/yii_lab/index.php&#63;r=lab/urlBoyLeeTest 
Copy after login

YII中怎使用model中的search

你这个方法写的没问题,但是如果是多表联查,不建议写在search方法里面,yii自动生成model的时候,一般会生成search方法,search方法一般作为该model的查询使用,即单独的一张表查询。

如果多张表联查,再写一个方法多好啊!而且,查询方法写在action中即可,多表查询没必要写在model里面啊

哈哈 以上只是个人习惯 仅供参考。

CActiveDataProvider 返回的查询结果,一般通过getData方法获取一个list数组,网上yii的例子很多,楼主随便查一下就明白了
 

Yii登陆 我想用自己的view模板页面,但是又想复用yii自带的验证登陆controller

controller, model和view本来就是独立的,你就直接套用你想要的view模板就好了,只要view表单中使用yii的CActiveForm widget就可以实现验证功能
 

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Where are themes located in Windows 11? Where are themes located in Windows 11? Aug 01, 2023 am 09:29 AM

Windows 11 has so many customization options, including a range of themes and wallpapers. While these themes are aesthetic in their own way, some users still wonder where they stand in the background on Windows 11. This guide will show you the different ways to access the location of your Windows 11 theme. What is the Windows 11 default theme? The default theme background of Windows 11 is an abstract royal blue flower blooming with a sky blue background. This background is one of the most popular, thanks to the anticipation before the release of the operating system. However, the operating system also comes with a range of other backgrounds. Therefore, you can change the Windows 11 desktop theme background at any time. Themes are stored in Windo

Different uses of slashes and backslashes in file paths Different uses of slashes and backslashes in file paths Feb 26, 2024 pm 04:36 PM

A file path is a string used by the operating system to identify and locate a file or folder. In file paths, there are two common symbols separating paths, namely forward slash (/) and backslash (). These two symbols have different uses and meanings in different operating systems. The forward slash (/) is a commonly used path separator in Unix and Linux systems. On these systems, file paths start from the root directory (/) and are separated by forward slashes between each directory. For example, the path /home/user/Docume

How to fix error: Main class not found or loaded in Java How to fix error: Main class not found or loaded in Java Oct 26, 2023 pm 11:17 PM

This video cannot be played due to a technical error. (Error Code: 102006) This guide provides simple fixes for this common problem and continue your coding journey. We will also discuss the causes of Java errors and how to prevent it in the future. What is "Error: Main class not found or loaded" in Java? Java is a powerful programming language that enables developers to create a wide range of applications. However, its versatility and efficiency come with a host of common mistakes that can occur during development. One of the interrupts is Error: Main class user_jvm_args.txt not found or loaded, which occurs when the Java Virtual Machine (JVM) cannot find the main class to execute a program. This error acts as a roadblock even in

What is the difference in the 'My Computer' path in Win11? Quick way to find it! What is the difference in the 'My Computer' path in Win11? Quick way to find it! Mar 29, 2024 pm 12:33 PM

What is the difference in the "My Computer" path in Win11? Quick way to find it! As the Windows system is constantly updated, the latest Windows 11 system also brings some new changes and functions. One of the common problems is that users cannot find the path to "My Computer" in Win11 system. This was usually a simple operation in previous Windows systems. This article will introduce how the paths of "My Computer" are different in Win11 system, and how to quickly find them. In Windows1

Get the directory portion of a file path using the path/filepath.Dir function Get the directory portion of a file path using the path/filepath.Dir function Jul 27, 2023 am 09:06 AM

Use the path/filepath.Dir function to obtain the directory part of the file path. In our daily development process, file path processing is often involved. Sometimes, we need to get the directory part of the file path, that is, the path to the folder where the file is located. In the Go language, you can use the Dir function provided by the path/filepath package to implement this function. The signature of the Dir function is as follows: funcDir(pathstring)string The Dir function receives a word

Linux kernel source code storage path analysis Linux kernel source code storage path analysis Mar 14, 2024 am 11:45 AM

The Linux kernel is an open source operating system kernel whose source code is stored in a dedicated code repository. In this article, we will analyze the storage path of the Linux kernel source code in detail, and use specific code examples to help readers better understand. 1. Linux kernel source code storage path The Linux kernel source code is stored in a Git repository called linux, which is hosted at [https://github.com/torvalds/linux](http

How to use the os.path module to obtain various parts of the file path in Python 3.x How to use the os.path module to obtain various parts of the file path in Python 3.x Jul 30, 2023 pm 02:57 PM

How to use the os.path module in Python3.x to obtain various parts of the file path. In daily Python programming, we often need to operate on the file path, such as obtaining the file name, file directory, extension, etc. of the path. In Python, you can use the os.path module to perform these operations. This article will introduce how to use the os.path module to obtain various parts of the file path for better file manipulation. The os.path module provides a series of

In JavaFX, what are the different path elements? In JavaFX, what are the different path elements? Aug 28, 2023 pm 12:53 PM

The javafx.scene.shape package provides some classes with which you can draw various 2D shapes, but these are just primitive shapes like lines, circles, polygons and ellipses etc... So if you want to draw complex For custom shapes, you need to use the Path class. Path class Path class You can draw custom paths using this geometric outline that represents a shape. To draw custom paths, JavaFX provides various path elements, all of which are available as classes in the javafx.scene.shape package. LineTo - This class represents the path element line. It helps you draw a straight line from the current coordinates to the specified (new) coordinates. HlineTo - This is the table

See all articles