YII 常用路径总结
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.*',
应用的主目录是指包含所有安全系数比较高的PHP代码和数据的根目录。
在默认情况下,这个目录一般是入口代码所在目录的一个目录: protected 。
这个路径可以通过在application configuration里设置 basePath来改变.
YII framework路径
Yii::getFrameworkPath()
YII 文件下载
Yii::app()->getRequest()->sendFile('test.txt', 'File content goes here.');
protected/runtime
Yii::app()->getRuntimePath();
protected/venders目录
Yii::import('application.venders.*');
或在protected/config/main.php说明
'import'=>array(
......
'application.venders.*',
),
插入meta信息
Yii::app()->clientScript->registerMetaTag('关键字','keywords');
Yii::app()->clientScript->registerMetaTag('一些描述','description');
Yii::app()->clientScript->registerMetaTag('作者','author');
Yii::app()->clientScript->registerMetaTag(' text/html;charset=utf-8', null, 'Content-Type');
<link rel="alternate" type="application/rss+xml" href="http://www.dreamdu.com/feed/" />
Yii::app()->clientScript->registerLinkTag('alternate','application/rss+xml',$this->createUrl('/feed'));
如何在控制器添加CSS文件或JavaScript文件
Yii::app()->clientScript->registerCssFile(Yii::app()->baseUrl.'/css/my.css');
Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl.'/css/my.js');
<?php echo $this->module->assetsUrl; ?>/css/main.css
调用YII框架中framework/web/js/source的js,其中registerCoreScript key调用的文件在framework/web/js/packages.php列表中可以查看
Yii::app()->clientScript->registerCoreScript('jquery');
在view中得到当前controller的ID方法:
Yii::app()->getController()->id;
在view中得到当前action的ID方法:
Yii::app()->getController()->getAction()->id;
yii获取ip地址
Yii::app()->request->userHostAddress;
yii判断提交方式
Yii::app()->request->isPostRequest isDeleteRequest isAjaxRequest
得到当前域名:
Yii::app()->request->hostInfo
得到proteced目录的物理路径
YII::app()->basePath;
得到模块名称
$module = Yii::app()->getModule()->getId();
获得上一页的url以返回
Yii::app()->request->urlReferrer;
得到当前url
Yii::app()->request->url;
得到当前home url
Yii::app()->homeUrl
得到当前return url
Yii::app()->user->returnUrl
项目路径
dirname(Yii::app()->BasePath)
Yii::app()->getBaseUrl(true);
<?php echo $this->getLayoutFile('main'); ?>
$this->redirect('index.php?r=admin/manage');
{createUrl()}
echo $this->createUrl('urlBoyLeeTest');
//out => /yii_lab/index.php?r=lab/urlBoyLeeTest
$this->createUrl('post/read') // /index.php/post/read
<?php echo Yii::app()->request->baseUrl; ?>/css/screen.css
Yii::app()->theme->baseUrl.'/images/FileName.gif'
{createAbsoluteUrl()}
echo $this->createAbsoluteUrl('urlBoyLeeTest');
//out => http://localhost/yii_lab/index.php?r=lab/urlBoyLeeTest
YII 常用路径总结的更多相关文章
- yii 常用路径
yii::app()->homeurl //主页的网址 yii系统变量. //得到proteced目录的物理路径 Yii::app()->basePath; 调用YII框架中jquery: ...
- Yii常用路径说明
原作者地址:http://www.kuitao8.com/20140520/2483.shtml //framework路径 Yii::getFrameworkPath(); //protected/ ...
- yii中常用路径<转>
调用YII框架中jquery:Yii::app()->clientScript->registerCoreScript(‘jquery’); framework/web/js/source ...
- Yii中常用路径(转)
调用YII框架中jquery:Yii::app()->clientScript->registerCoreScript('jquery'); framework/web/js/sou ...
- yii中常用路径
//YII framework路径Yii::getFrameworkPath(); //protected/runtimeYii::app()->getRuntimePath(); //在vie ...
- Yii常用技巧总结
//YII framework路径 Yii::getFrameworkPath(); //protected/runtime Yii::app()->getRuntimePath(); //pr ...
- 常用路径 URL 中的斜杠与反斜杠
常用路径中的斜杠与反斜杠... ------------------------------ 斜杠:反斜杠:======================电脑能识别的斜杠有两种:斜杠分正斜杠(forwa ...
- yii常用操作数据
yii常用操作数据.php <?php defined('YII_DEBUG') or define('YII_DEBUG', true); //当在调试模式下,应用会保留更多日志信息,如果抛出 ...
- Load_file 常用路径
load_file 常用路径 WINDOWS下: c:/boot.ini //查看系统版本 c:/windows/php.ini //php配置信息 c:/windows/my.ini //MYSQL ...
随机推荐
- 最近遇到的两个IE下的问题(IE兼容问题)
最近遇到了两个IE下的兼容问题(产品目前还需要兼容IE8,所以没办法,运行效果虽然不好,但是也仍然兼容着吧) 问题描述: 1, 在更改IE窗口的时候,反应非常慢,甚至卡死 2, 在chrome运行正常 ...
- react学习笔记-02
1.组件嵌套 React允许将代码封装成一个component,然后像html标签一样,插入网页中中. var HelloMessage = React.createClass({ render: f ...
- Docker 安装及问题处理
1 确定Linux版本 uname -r 2 升级系统(添加 APT 镜像源,添加使用 HTTPS 传输的软件包以及 CA 证书.) sudo apt-get update sudo apt-get ...
- php系统无法上传图片问题
PHP Warning: File upload error - unable to create a temporary file in Unknown on line 0 我的测试环境是 w ...
- 32bit程序在64bit操作系统下处理重定向细节(转自http://bbs.pediy.com/showthread.php?t=89054)
1. 64bit操作系统的重定向机制以及目的 在64bit操作系统中,为了无缝兼容32bit程序的运行,64bit的Windows操作系统采用重定向机制.目的是为了能让32bit程序在64bit的操作 ...
- 基于HTML5 的WebSql本地设备数据库
HTML5 的 Web SQL Database 用本地和会话存储实现简单的对象持久化,对繁琐的关系数据进行处理. 在 W3C 的 Web SQL Database 规范中(参照 介绍)有这样的描述: ...
- .net core 单元测试小记
创建项目,选择.net core的类库(class library) 修改project.json的配置 { "version": "1.0.0-*", &qu ...
- push类型消息中间件-消息发布者(二)
1.消息发布者声明 我们以spring的方式来声明一个消息发布者: <bean id="operateLogsMessageManager" class="com. ...
- 【第四篇】Volley修改之GsonRequest
json解析工具类的引入,这里引用lite马天宇的解析json的工具类: public class GsonImpl extends Json { private Gson gson = new Gs ...
- 【第一篇】Volley的使用之json请求
最近项目写完,有开始新的学习了,volley很久以前就接触了,也看了源码,然而却没有通过文章去记录自己的学习成果. 首先讲下volley的特点: 1,扩展性强.Volley 中大多是基于接口的设计,可 ...