Zend Framework 入门

php中文网
发布: 2016-07-30 13:31:52
原创
1374人浏览过

一.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

在命令行下输入:


小门道AI
小门道AI

小门道AI是一个提供AI服务的网站

小门道AI 117
查看详情 小门道AI

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


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

七.    Create a Model andDatabase Table

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

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

八.    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教程有兴趣的朋友有所帮助。

相关标签:
最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号