yii学习笔记--url解析

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解析的更多相关文章
- Web.py 框架学习笔记 - URL处理
最近由于工作需要开始学习基于python的web应用框架web.py.为了方便学习,将学习心得逐日记下以便日后复习. URL 模板: web.py提供了一套url处理的模板,在python工程中,只需 ...
- yii学习笔记(1),目录结构和请求过程
最近找找工作面试,发现很多要求会yii.于是准备学习一个新的框架 先在腾讯课堂找了个视频看了一下,然后去网上现在了“归档文件”(还有一种方式是通过php的包管理工具“composer”安装) 归档文件 ...
- yii学习笔记
学而不思则罔,思而不学则殆,适度的总结有利于学习效果的提升. 以前就是埋头看书很少动手所以学习效果不好. 学习yii的原因是自己基本功差,但是yii的学习本身也需要成本
- HTTP学习笔记——URL与资源
什么是URL? 所有的东西都有一个标准化的东西,公交有线路号,飞机有航班号,个人有身份证号,你坐出租车,告诉司机师傅我要到石牌华师,他就能明白你的意思了.URL就是因特网资源的标准化名称.URL指向一 ...
- java学习笔记DOM4J解析(7)
DOM4J即Document Object Model for Java使用java技术以文档方式解析XML数据的模型. DOM4J是开源组织提供的一个免费的.强大的XML解析工具,如果开发者需要在项 ...
- yii学习笔记(2),创建控制器
将网站根目录配置到项目的web目录 打开网站访问的是web/index.php这时打开默认页面 访问一下其他页面,发现浏览器地址的url携带了一个参数 http://www.test.com/inde ...
- yii学习笔记(四)
return $this->goBack(); // 先看看Yii::$app->user->returnUrl是否已经设置, returnUrl没有设置且goBack()中的参数也 ...
- Yii 学习笔记
Yii常用执行SQL方法 ====================================================== ================================ ...
- HTML 学习笔记(URL)
URL也被称为网址 URL可以由单词组成,比如"www.baidu.com" 或者是因特网协议IP地址:192.168.1.253.大多数人在网上冲浪时,会键入网址的域名,因为名称 ...
随机推荐
- docker常用操作备忘
一.docker安装 参考资料:阿里云镜像加速1. 安装/升级Docker客户端 curl -fsSL https://get.docker.com | bash -s docker --mirror ...
- get通配符
这篇文章是在上一篇常用正则表达式(合) https://blog.csdn.net/yeyeye200/article/details/86186889 基础上的延伸:关于通配符的使用~ 一开始get ...
- MyBatis中<if test=" ">标签条件不起作用
问题产生? 今天在做Excel导出的时候,有个判断一个状态的字段,我的这个字段是int类型的,还有两个时间类型,我在判断的时候给的是Long类型的. 在测试的时候发现,不管怎么样都不执行if条件里面的 ...
- java多线程中注入Spring对象问题
web应用中java多线程并发处理业务时,容易抛出NullPointerException. 原因: 线程中的Spring Bean没有被注入.web容器在启动时,没有提前将线程中的bean注入,在线 ...
- 20175316盛茂淞 2018-2019-2 《Java程序设计》第8周学习总结
20175316盛茂淞 2018-2019-2 <Java程序设计>第8周学习总结 教材学习内容总结 第十五章 泛型 -- 主要目的是可以建立具有类型安全的集合框架,如链表.散列映射等数据 ...
- MyEclipse has detected that less than 5% of
选择Windows->Preferences; 2 选择MyEclipse->Servers->Integrated Sandbox->MyEclispe Tomcat 6 ...
- Shiro学习
Shiro学习资源 Shiro官网,http://shiro.apache.org/index.html 学习网站链接,http://blog.java1234.com/blog/articles/4 ...
- vue中引入vux
1.安装相关依赖 cnpm install vux --save cnpm install vux-loader --save-dev cnpm install less less-loader -- ...
- 效果监控js源码
function _bxmPlatformFn(e, t) { var n, o, i = ""; try { i = localStorage.getItem("lis ...
- Python Flask学习笔记之模板
Python Flask学习笔记之模板 Jinja2模板引擎 默认情况下,Flask在程序文件夹中的templates子文件夹中寻找模板.Flask提供的render_template函数把Jinja ...