在ZF中的MVC结构中,目录结构是这样的:
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
在Apache中新建一个alias,目录指向html/下,.htaccess是apache的目录配置文件,里面存放了一些指令,可以改变apache的一些访问规则,比如404出错提示信息等等,我们这里要放的是urlrewrite,URL重定向信息。
将以下信息复制到.htaccess中:
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
这样,index.php就接收了该站所有的请求,这时候index.php就被称为 bootstrap 文件,所谓bootstrap,就是一小段引导程序或者入口程序,index.php的内容如下:
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
以上代码的意思是启动Zend_Controller_Front,ZendFront是前端控制器,负责解析URL,将请求分配给不同的控制器。
然后我们创建一个默认的控制器,在application/controllers目录下创建一个IndexController.php文件,内容如下:
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
一个控制器就建立好了,可以看到,控制器就是从Zend_Conttroller_Action继承的一个类,并且以Controller结尾,这是ZendFramework的MVC结构中的约定,而URL中的第一部分会被解释为控制器,并与我们这里所创建的控制器一一对应起来。
IndexConttroller类中有一个方法,叫做indexAction,这个方法与URL中的第二部分对应起来。
也就是说,上面建立的这个IndexController控制器的IndexAction方法,对应的URL就是: /index/index,访问这个URL就会调用indexAction方法。
在默认情况下,ViewRenderer是启用的。