Zend Framework 入门


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


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

其中也包含了指令用来设置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 = '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,
       ));
    }
}
 


 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值