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

system: 指向Yii框架目录; YII\framework

zii: 指向zii library 目录; YII\framework\zii

application : 指向应用程序基本目录;  protected\

webroot: 指向包含里入口脚本 文件的目录. 此别名自 1.0.3 版起生效. \

ext : 指向包含所有第三方扩展的目录, 从版本 1.0.8 可用;  \protected\extensions

  1. Yii::getPathOfAlias('zii')

  2. Yii::import ('zii.*')

  3. Yii::setPathOfAlias('backend', $backend);

  4. 'import' => array(

  5. 'backend.models.*',

应用的主目录是指包含所有安全系数比较高的PHP代码和数据的根目录。

在默认情况下,这个目录一般是入口代码所在目录的一个目录: protected 。

这个路径可以通过在application configuration里设置 basePath来改变.

YII framework路径

  1. Yii::getFrameworkPath()

YII 文件下载

  1. Yii::app()->getRequest()->sendFile('test.txt', 'File content goes here.');

protected/runtime

  1. Yii::app()->getRuntimePath();

protected/venders目录

  1. Yii::import('application.venders.*');

或在protected/config/main.php说明

  1. 'import'=>array(

  2. ......

  3. 'application.venders.*',

  4. ),

插入meta信息

  1. Yii::app()->clientScript->registerMetaTag('关键字','keywords');

  2. Yii::app()->clientScript->registerMetaTag('一些描述','description');

  3. Yii::app()->clientScript->registerMetaTag('作者','author');

  4. 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/" />

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

如何在控制器添加CSS文件或JavaScript文件

  1. Yii::app()->clientScript->registerCssFile(Yii::app()->baseUrl.'/css/my.css');

  2. Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl.'/css/my.js');

  3. <?php echo $this->module->assetsUrl; ?>/css/main.css

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

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

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

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

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

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

yii获取ip地址

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

yii判断提交方式

  1. Yii::app()->request->isPostRequest isDeleteRequest isAjaxRequest

得到当前域名:

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

得到proteced目录的物理路径

  1. YII::app()->basePath;

得到模块名称

  1. $module = Yii::app()->getModule()->getId();

获得上一页的url以返回

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

得到当前url

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

得到当前home url

  1. Yii::app()->homeUrl

得到当前return url

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

项目路径

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

  2. Yii::app()->getBaseUrl(true);

<?php echo $this->getLayoutFile('main'); ?>

$this->redirect('index.php?r=admin/manage');

{createUrl()}

  1. echo $this->createUrl('urlBoyLeeTest');

  2. //out => /yii_lab/index.php?r=lab/urlBoyLeeTest

  3. $this->createUrl('post/read') // /index.php/post/read

  1. <?php echo Yii::app()->request->baseUrl; ?>/css/screen.css

  2. Yii::app()->theme->baseUrl.'/images/FileName.gif'

{createAbsoluteUrl()}

    1. echo $this->createAbsoluteUrl('urlBoyLeeTest');

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

    3.  

YII 常用路径总结的更多相关文章

  1. yii 常用路径

    yii::app()->homeurl //主页的网址 yii系统变量. //得到proteced目录的物理路径 Yii::app()->basePath; 调用YII框架中jquery: ...

  2. Yii常用路径说明

    原作者地址:http://www.kuitao8.com/20140520/2483.shtml //framework路径 Yii::getFrameworkPath(); //protected/ ...

  3. yii中常用路径<转>

    调用YII框架中jquery:Yii::app()->clientScript->registerCoreScript(‘jquery’); framework/web/js/source ...

  4. Yii中常用路径(转)

    调用YII框架中jquery:Yii::app()->clientScript->registerCoreScript('jquery');    framework/web/js/sou ...

  5. yii中常用路径

    //YII framework路径Yii::getFrameworkPath(); //protected/runtimeYii::app()->getRuntimePath(); //在vie ...

  6. Yii常用技巧总结

    //YII framework路径 Yii::getFrameworkPath(); //protected/runtime Yii::app()->getRuntimePath(); //pr ...

  7. 常用路径 URL 中的斜杠与反斜杠

    常用路径中的斜杠与反斜杠... ------------------------------ 斜杠:反斜杠:======================电脑能识别的斜杠有两种:斜杠分正斜杠(forwa ...

  8. yii常用操作数据

    yii常用操作数据.php <?php defined('YII_DEBUG') or define('YII_DEBUG', true); //当在调试模式下,应用会保留更多日志信息,如果抛出 ...

  9. Load_file 常用路径

    load_file 常用路径 WINDOWS下: c:/boot.ini //查看系统版本 c:/windows/php.ini //php配置信息 c:/windows/my.ini //MYSQL ...

随机推荐

  1. wall time

    "showing elapsed time and wall clock time correspondingly." what's difference between elap ...

  2. channel bonding

    一.什么是bondingLinux bonding驱动提供了一个把多个网络接口设备捆绑为单个的网络接口设置来使用,用于网络负载均衡及网络冗余二.bonding应用方向1.网络负载均衡对于bonding ...

  3. python获取

    def anc():pass print anc.__name__ def timeit(func): def run(*argv): print "this function name i ...

  4. Apache环境服务器配置Let's Encrypt免费SSL证书及自动续期方法

    如今越来越多的网站开始使用SSL证书,实现HTTPS网址形式,如果我们是英文网站更需要用到这样格式的HTTPS网址,因为根据谷歌搜索结果提示到如果用到SSL证书的在同等条件下排名结果是有靠前可能的.我 ...

  5. day01(RESTful Web Service、SVN)

    今日大纲 搭建SSM环境 基于SSM环境实现用户管理系统 学习RESTful Web Service 学习SVN 统一开发环境 JDK1.7 32? 64? -- 64 Eclipse 使用4.4.1 ...

  6. 《JS权威指南学习总结--6.1原型》

    内容要点: 一.每一个JS对象(null除外)都和另一个对象相关联."另一个"对象就是我们熟知的原型,每一个对象都从原型继承属性. 二.所有通过对象直接量创建的对象都具有同一个原型 ...

  7. Eclipse Kepler maven工程配置JDK1.8

    首先需要下载插件:"Help" --> "Market Place" --> Search for java 8 kepler. install J ...

  8. 【Unity】Unity中C#与Android中Java的互相调用遇到的一些问题

    1.有关调用的一些问题: (1).在C#中直接调用java中的代码,无返回值: 在java中: public static void setAge(Context context , int leve ...

  9. (转)了解JNDI

    JNDI是 Java 命名与目录接口(Java Naming and Directory Interface),在J2EE规范中是重要的规范之一,不少专家认为,没有透彻理解JNDI的意义和作用,就没有 ...

  10. dubbo 分布式架构学习视频链接

    http://www.roncoo.com/course/view/f614343765bc4aac8597c6d8b38f06fd 书籍 大型分布式网站架构设计与实践 http://item.jd. ...