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.大多数人在网上冲浪时,会键入网址的域名,因为名称 ...
随机推荐
- Python 列表(list)的使用
文章目录 一.创建list 二.访问list中元素 三.更新元素 四.删除元素 五.求list长度 六.连接列表 七.截取列表 八.复制列表 一.创建list myList = [2,3,1,5,6, ...
- 【机器学习】支持向量机(SVM)的优化算法——序列最小优化算法(SMO)概述
SMO算法是一一种启发式算法,它的基本思路是如果所有变量的解的条件都满足最优化问题的KKT条件,那么这个最优化问题的解就得到了.因为KKT条件是该优化问题的充分必要条件. 整个SMO算法包括两个部分: ...
- AJAX随笔1
[1] AJAX简介 > 全称: Asynchronous JavaScript And XML > 异步的JavaScript和XML > AJAX就是通过JavaSc ...
- vue 导航守卫,验证是否登录
路由跳转前,可以用导航守卫判断是否登录,如果登录了就正常跳转,没有登录就把路由指向登录页面. router.beforeEach((to, from, next) => { const next ...
- 从Excel表中导入数据时日期格式的验证问题解决
#region IsDateTimeType 私有方法判断导入数据是否是日期格式 /// <summary> /// 私有方法判断导入数据是否是日期格式 /// </summary& ...
- Win7 VS2017 Boost Python入门
闲来无事想练习下用Python作为游戏脚本绑定到C++,网上搜了下,Python文档有些例子,但是太过复杂,gayhub无意中看到有人用Boost Python绑定,简单粗暴,省时省力,记录备忘. 写 ...
- 1021. Deepest Root DFS 求最长无环路径
第一次出现超时 ac不了的题 思路一:对于每个节点用一次dfs dfs中 记录到当前的最长路径,若大于最长,则清除set,并加入当前节点 思路二:先查找只有一个相邻节点的节点进行dfs,由于可能存在闭 ...
- post文件下载
this.$http({ method: 'post', url: '/file/download', responseType: 'blob', data: JSON.stringify(this. ...
- C++ STL next_permutation(快速排列组合)
排列组合必备!! https://blog.csdn.net/bengshakalakaka/article/details/78515480
- Go学习之旅
备忘这个 官方文档 https://go-zh.org/doc/ Go指南 https://tour.go-zh.org/welcome/1 Go语言圣经 https://yar999.gitbook ...