在通过yiic命令生成了一个app之后,我们通过浏览器访问会看到这样的一个页面。
 
  点击home时,url为:http://localhost/blog/index.php?r=site/index
  点击about时,url为:http://localhost/blog/index.php?r=site/page&view=about
  但是,实际上他们都对应于不同的脚本。app在一个名叫 urlManager 的应用组件的帮助下,决定请求的控制和动作,以上的两个请求都对应于同一个控制器site,我们可以在/protected/controllers/ 目录下找到控制器:SiteController.php(如下),class SiteController 继承于 Controller,在SiteController里面会定义处理请求的动作方法,比如function actionIndex () {};他用于处理url为:http://localhost/blog/index.php?r=site/index 这个请求。而对于url为:http://localhost/blog/index.php?r=site/page&view=about,我们并未找到 function actionPage () {};而且我们可以看到与其他url不同的是,这个请求还附带了一个参数 view=about,其实这类请求都在function actions () {};中进行处理,对于这个请求,它会到/protected/views/site/pages 下面寻找 about.php页面。
    
 ?php

 class SiteController extends Controller
{
/**
* Declares class-based actions.
*/
public function actions()
{
return array(
// captcha action renders the CAPTCHA image displayed on the contact page
'captcha'=>array(
'class'=>'CCaptchaAction',
'backColor'=>0xFFFFFF,
),
// page action renders "static" pages stored under 'protected/views/site/pages'
// They can be accessed via: index.php?r=site/page&view=FileName
'page'=>array(
'class'=>'CViewAction',
),
);
} /**
* This is the default 'index' action that is invoked
* when an action is not explicitly requested by users.
*/
public function actionIndex()
{
// renders the view file 'protected/views/site/index.php'
// using the default layout 'protected/views/layouts/main.php'
$this->render('index');
} /**
* This is the action to handle external exceptions.
*/
public function actionError()
{
if($error=Yii::app()->errorHandler->error)
{
if(Yii::app()->request->isAjaxRequest)
echo $error['message'];
else
$this->render('error', $error);
}
}/**
* Displays the contact page
*/
public function actionContact()
{
$model=new ContactForm;
if(isset($_POST['ContactForm']))
{
$model->attributes=$_POST['ContactForm'];
if($model->validate())
{
$name='=?UTF-8?B?'.base64_encode($model->name).'?=';
$subject='=?UTF-8?B?'.base64_encode($model->subject).'?=';
$headers="From: $name <{$model->email}>\r\n".
"Reply-To: {$model->email}\r\n".
"MIME-Version: 1.0\r\n".
"Content-type: text/plain; charset=UTF-8"; mail(Yii::app()->params['adminEmail'],$subject,$model->body,$headers);
Yii::app()->user->setFlash('contact','Thank you for contacting us. We will respond to you as soon as possible.');
$this->refresh();
}
}
$this->render('contact',array('model'=>$model));
}/**
* Displays the login page
*/
public function actionLogin()
{
$model=new LoginForm; // if it is ajax validation request
if(isset($_POST['ajax']) && $_POST['ajax']==='login-form')
{
echo CActiveForm::validate($model);
Yii::app()->end();
} // collect user input data
if(isset($_POST['LoginForm']))
{
$model->attributes=$_POST['LoginForm'];
// validate user input and redirect to the previous page if valid
if($model->validate() && $model->login())
$this->redirect(Yii::app()->user->returnUrl);
}
// display the login form
$this->render('login',array('model'=>$model));
} /**
* Logs out the current user and redirect to homepage.
*/
public function actionLogout()
{
Yii::app()->user->logout();
$this->redirect(Yii::app()->homeUrl);
}
}

yii学习笔记--url解析的更多相关文章

  1. Web.py 框架学习笔记 - URL处理

    最近由于工作需要开始学习基于python的web应用框架web.py.为了方便学习,将学习心得逐日记下以便日后复习. URL 模板: web.py提供了一套url处理的模板,在python工程中,只需 ...

  2. yii学习笔记(1),目录结构和请求过程

    最近找找工作面试,发现很多要求会yii.于是准备学习一个新的框架 先在腾讯课堂找了个视频看了一下,然后去网上现在了“归档文件”(还有一种方式是通过php的包管理工具“composer”安装) 归档文件 ...

  3. yii学习笔记

    学而不思则罔,思而不学则殆,适度的总结有利于学习效果的提升. 以前就是埋头看书很少动手所以学习效果不好. 学习yii的原因是自己基本功差,但是yii的学习本身也需要成本

  4. HTTP学习笔记——URL与资源

    什么是URL? 所有的东西都有一个标准化的东西,公交有线路号,飞机有航班号,个人有身份证号,你坐出租车,告诉司机师傅我要到石牌华师,他就能明白你的意思了.URL就是因特网资源的标准化名称.URL指向一 ...

  5. java学习笔记DOM4J解析(7)

    DOM4J即Document Object Model for Java使用java技术以文档方式解析XML数据的模型. DOM4J是开源组织提供的一个免费的.强大的XML解析工具,如果开发者需要在项 ...

  6. yii学习笔记(2),创建控制器

    将网站根目录配置到项目的web目录 打开网站访问的是web/index.php这时打开默认页面 访问一下其他页面,发现浏览器地址的url携带了一个参数 http://www.test.com/inde ...

  7. yii学习笔记(四)

    return $this->goBack(); // 先看看Yii::$app->user->returnUrl是否已经设置, returnUrl没有设置且goBack()中的参数也 ...

  8. Yii 学习笔记

    Yii常用执行SQL方法 ====================================================== ================================ ...

  9. HTML 学习笔记(URL)

    URL也被称为网址 URL可以由单词组成,比如"www.baidu.com" 或者是因特网协议IP地址:192.168.1.253.大多数人在网上冲浪时,会键入网址的域名,因为名称 ...

随机推荐

  1. 实现一个简易版的SpringMvc框架

    先来看我们的程序入口DispatcherServlet 主要核心处理流程如下: 1 扫描基础包下的带有controller 以及 service注解的class,并保存到list中 2 对第一步扫描到 ...

  2. Python3 安装basemap

    1,https://www.lfd.uci.edu/~gohlke/pythonlibs/ 下载basemap和pyproj的地址 打开网页,搜索basemap和pyproj 下载相应的安装包,安装这 ...

  3. redis多实例

    1.首先在发布系统: 2.安装多实例利用cmd命令安装,切换目录到redis下 (1)首先拷贝一个redis的conf文件(如redis_6380.conf),并且修改里面的服务端口号.日志端口号,以 ...

  4. e.stopPropagation()兼容性处理

    使用jquery库,e.stopPropagation()兼容所有. 原生的就要这么写 function stopPropagation(e){ e=window.event||e; if(docum ...

  5. JupyterLab绘制:柱状图,饼状图,直方图,散点图,折线图

    JupyterLab绘图 喜欢python的同学,可以到 https://v3u.cn/(刘悦的技术博客) 里面去看看,爬虫,数据库,flask,Django,机器学习,前端知识点,JavaScrip ...

  6. 让Spring Boot项目启动时可以根据自定义配置决定初始化哪些Bean

    让Spring Boot项目启动时可以根据自定义配置决定初始化哪些Bean 问题描述 实现思路 思路一 [不符合要求] 思路二[满足要求] 思路三[未试验] 问题描述 目前我工作环境下,后端主要的框架 ...

  7. Python Flask学习笔记之Hello World

    Python Flask学习笔记之Hello World 安装virtualenv,配置Flask开发环境 virtualenv 虚拟环境是Python解释器的一个私有副本,在这个环境中可以安装私有包 ...

  8. thinkphp添加数据 add()方法

    thinkphpz内置的add()方法用于向数据库表添加数据,相当于SQL中的INSERT INTO 行为添加数据 add 方法是 CURD(Create,Update,Read,Delete / 创 ...

  9. 利用Qt Designer 进行 空间提升propomotion 的时候异常: NO such file or directory

    1. 因为在提升的时候,只设置了 类名,以及文件名,但是没有给定Qt 的uic 的指定搜索路径,因此报错 在生成的ui_xxxx.h文件必然找不到这个文件. 如下图: 2. 解决方法 在项目的属性中: ...

  10. 记录一下msf的学习使用

    刚刚用Metasploit Pro scan了一下云端服务器.RHOST直接输IP就好. 得到反馈如下: [*] [2019.04.04-14:27:35] Scan initiated: Speed ...