首页 后端开发 php教程 Zend Framework 入门

Zend Framework 入门

Jul 30, 2016 pm 01:31 PM
application bootstrap controller display

一.Create YourProject

详细请看这篇文章:

http://blog.csdn.net/u012675743/article/details/45511019

二.The BootStrap

Bootstrap用来定义你的项目资源和组件初始化。类如下:

//application/Bootstrap.php
 
class Bootstrapextends Zend_Application_Bootstrap_Bootstrap
{
}
登录后复制

详细还可以参考这篇文章:

http://blog.csdn.net/u012675743/article/details/45510903


三.Configuration

经常需要自己配置应用,默认配置文件在<em>application/configs/application.ini</em>,

其中也包含了指令用来设置PHP环境,声明bootstrap路径,

; application/configs/application.ini


[production]
phpSettings.display_startup_errors = 0
phpSettings.display_errors = 0
includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"


[staging : production]


[testing : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1


[development : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
登录后复制

四.Action Controllers

一个controller应该有一个或者多个methods,这些methods可以通过浏览器被请求。通常可以写一个indexcontroller,作为站点的主页。
默认的indexcontroller为下:

// application/controllers/IndexController.php

class IndexController extends Zend_Controller_Action
{
    public function init()
    {
        /* Initialize action controller here */
    }
    public function indexAction()
    {
        // action body
    }
}
登录后复制

五.Views

每个controller都在application/views/scripts/下有一个对应的视图。并相应的命名为 ‘controller/controller.phtml’,主要写前台要展示的页面。


六.Create A Layout

在命令行下输入:


记得一定要切换到工程文件夹下,否则会出现如下提示:


然后打开layouts文件夹下,会出现一个scripts文件夹。

七.    Create a Model andDatabase Table

对数据库中要操作的每一个表都需要写一个表类,$_primary为表的主键,例如:

<?php class Book extends Zend_Db_Table{
    protected $_name = &#39;book&#39;;
    protected $_primary = &#39;id&#39;;
}
登录后复制

八.    Create A Form

使用框架的form来提交数据的入口是非常方便的。在application下创建目录forms,即application/forms,并创建相应的form class。

例如:

<?php class Application_Form_Guestbook extendsZend_Form
{
 
   public function init()
    {
       // Set the method for the display form to POST
       $this->setMethod('post');
 
       // Add an email element
       $this->addElement('text', 'email', array(
           'label'      => 'Your emailaddress:',
           'required'   => true,
           'filters'    =>array('StringTrim'),
           'validators' => array(
                'EmailAddress',
           )
       ));
 
       // Add the comment element
       $this->addElement('textarea', 'comment', array(
           'label'      => 'PleaseComment:',
           'required'   => true,
           'validators' => array(
                array('validator' =>'StringLength', 'options' => array(0, 20))
                )
       ));
 
       // Add a captcha
       $this->addElement('captcha', 'captcha', array(
           'label'      => 'Please enterthe 5 letters displayed below:',
           'required'   => true,
           'captcha'    => array(
                'captcha' => 'Figlet',
               'wordLen' => 5,
                'timeout' => 300
           )
       ));

       // Add the submit button
       $this->addElement('submit', 'submit', array(
           'ignore'   => true,
           'label'    => 'Sign Guestbook',
       ));
 
       // And finally add some CSRF protection
       $this->addElement('hash', 'csrf', array(
           'ignore' => true,
       ));
    }
}
 
登录后复制

 


版权声明:本文为博主原创文章,未经博主允许不得转载。

以上就介绍了Zend Framework 入门,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

AI Hentai Generator

AI Hentai Generator

免费生成ai无尽的。

热工具

记事本++7.3.1

记事本++7.3.1

好用且免费的代码编辑器

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用

禅工作室 13.0.1

禅工作室 13.0.1

功能强大的PHP集成开发环境

Dreamweaver CS6

Dreamweaver CS6

视觉化网页开发工具

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)

bootstrap搜索栏怎么获取 bootstrap搜索栏怎么获取 Apr 07, 2025 pm 03:33 PM

如何使用 Bootstrap 获取搜索栏的值:确定搜索栏的 ID 或名称。使用 JavaScript 获取 DOM 元素。获取元素的值。执行所需的操作。

vue中怎么用bootstrap vue中怎么用bootstrap Apr 07, 2025 pm 11:33 PM

在 Vue.js 中使用 Bootstrap 分为五个步骤:安装 Bootstrap。在 main.js 中导入 Bootstrap。直接在模板中使用 Bootstrap 组件。可选:自定义样式。可选:使用插件。

bootstrap怎么写分割线 bootstrap怎么写分割线 Apr 07, 2025 pm 03:12 PM

创建 Bootstrap 分割线有两种方法:使用 标签,可创建水平分割线。使用 CSS border 属性,可创建自定义样式的分割线。

bootstrap垂直居中怎么弄 bootstrap垂直居中怎么弄 Apr 07, 2025 pm 03:21 PM

使用 Bootstrap 实现垂直居中:flexbox 法:使用 d-flex、justify-content-center 和 align-items-center 类,将元素置于 flexbox 容器内。align-items-center 类法:对于不支持 flexbox 的浏览器,使用 align-items-center 类,前提是父元素具有已定义的高度。

bootstrap怎么调整大小 bootstrap怎么调整大小 Apr 07, 2025 pm 03:18 PM

要调整 Bootstrap 中元素大小,可以使用尺寸类,具体包括:调整宽度:.col-、.w-、.mw-调整高度:.h-、.min-h-、.max-h-

bootstrap怎么设置框架 bootstrap怎么设置框架 Apr 07, 2025 pm 03:27 PM

要设置 Bootstrap 框架,需要按照以下步骤:1. 通过 CDN 引用 Bootstrap 文件;2. 下载文件并将其托管在自己的服务器上;3. 在 HTML 中包含 Bootstrap 文件;4. 根据需要编译 Sass/Less;5. 导入定制文件(可选)。设置完成后,即可使用 Bootstrap 的网格系统、组件和样式创建响应式网站和应用程序。

Bootstrap Table使用AJAX获取数据出现乱码怎么办 Bootstrap Table使用AJAX获取数据出现乱码怎么办 Apr 07, 2025 am 11:54 AM

使用AJAX从服务器获取数据时Bootstrap Table出现乱码的解决方法:1. 设置服务器端代码的正确字符编码(如UTF-8)。2. 在AJAX请求中设置请求头,指定接受的字符编码(Accept-Charset)。3. 使用Bootstrap Table的"unescape"转换器将已转义的HTML实体解码为原始字符。

bootstrap怎么插入图片 bootstrap怎么插入图片 Apr 07, 2025 pm 03:30 PM

在 Bootstrap 中插入图片有以下几种方法:直接插入图片,使用 HTML 的 img 标签。使用 Bootstrap 图像组件,可以提供响应式图片和更多样式。设置图片大小,使用 img-fluid 类可以使图片自适应。设置边框,使用 img-bordered 类。设置圆角,使用 img-rounded 类。设置阴影,使用 shadow 类。调整图片大小和位置,使用 CSS 样式。使用背景图片,使用 background-image CSS 属性。

See all articles