无为清净楼资源网 Design By www.qnjia.com
1.首先让我们设置一下我们的程序,让Zend能够自动载入方法,不需要我们手动的去载入
复制代码 代码如下:
require_once 'Zend/Loader/Autoloader.php' //载入自动加载类
$loader = Zend_Loader_Autoloader::getInstance();//自动实例化
$loader->registerNamespace('Application_');//注册命名空间(只有系统默认的,和注册的才可以被自动载入)
$loader->registerNamespace(array('Foo_', 'Bar_')); //多个命名空间的注册方法
$loader->setFallbackAutoloader(true); //一个增加消耗的方法,不需要命名空间,直接载入所有类(不被推荐使用)
然后请注意,你的包含目录是否已经包含了,你自己的需被载入的目录
复制代码 代码如下:
set_include_path(implode(PATH_SEPARATOR, array(
realpath(APPLICATION_PATH . '/../library'),
realpath(APPLICATION_PATH . '/forms/'),
get_include_path(),
)));
//这里我们包含了我们的forms目录,方便程序的被载入
2.确认下form的目录
在application/forms/下 建立一个 Guestbook.phps
作为我们form的类文件,如下:
复制代码 代码如下:
<?php
class Application_Form_Guestbook extends Zend_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 email address:',
'required' => true,
'filters' => array('StringTrim'),
'validators' => array(
'EmailAddress',
)
));
// Add the comment element
$this->addElement('textarea', 'comment', array(
'label' => 'Please Comment:',
'required' => true,
'validators' => array(
array('validator' => 'StringLength', 'options' => array(0, 20))
)
));
// Add a captcha
$this->addElement('captcha', 'captcha', array(
'label' => 'Please enter the 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,
));
}
}
然后添加一个路由控制文件
applictaion/controller/GuestbookController.php
复制代码 代码如下:
<?php
class GuestbookController extends Zend_Controller_Action
{
// snipping indexAction()...
public function signAction()
{
$request = $this->getRequest();//获取接受到得信息
// include_once("../application/forms/Guestbook.php"); 手动加载类,只有不能自动载入时,才需要
$form = new Application_Form_Guestbook;//实例化这个方法
if ($this->getRequest()->isPost()) {//如果是POST传递的结果
if ($form->isValid($request->getPost())) {//判断传递是否有效
$comment = new Application_Model_Guestbook($form->getValues());
$mapper = new Application_Model_GuestbookMapper();
$mapper->save($comment);
return $this->_helper->redirector('index');
}
}
$this->view->form = $form;//将表单赋值给试图
}
}
最后添加一个简单的sign视图文件即可:
地址:application/views/scripts/guestbook/sgin.php
复制代码 代码如下:
Please use the form below to sign our guestbook!
<?php
$this->form->setAction($this->url());
echo $this->form;
复制代码 代码如下:
require_once 'Zend/Loader/Autoloader.php' //载入自动加载类
$loader = Zend_Loader_Autoloader::getInstance();//自动实例化
$loader->registerNamespace('Application_');//注册命名空间(只有系统默认的,和注册的才可以被自动载入)
$loader->registerNamespace(array('Foo_', 'Bar_')); //多个命名空间的注册方法
$loader->setFallbackAutoloader(true); //一个增加消耗的方法,不需要命名空间,直接载入所有类(不被推荐使用)
然后请注意,你的包含目录是否已经包含了,你自己的需被载入的目录
复制代码 代码如下:
set_include_path(implode(PATH_SEPARATOR, array(
realpath(APPLICATION_PATH . '/../library'),
realpath(APPLICATION_PATH . '/forms/'),
get_include_path(),
)));
//这里我们包含了我们的forms目录,方便程序的被载入
2.确认下form的目录
在application/forms/下 建立一个 Guestbook.phps
作为我们form的类文件,如下:
复制代码 代码如下:
<?php
class Application_Form_Guestbook extends Zend_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 email address:',
'required' => true,
'filters' => array('StringTrim'),
'validators' => array(
'EmailAddress',
)
));
// Add the comment element
$this->addElement('textarea', 'comment', array(
'label' => 'Please Comment:',
'required' => true,
'validators' => array(
array('validator' => 'StringLength', 'options' => array(0, 20))
)
));
// Add a captcha
$this->addElement('captcha', 'captcha', array(
'label' => 'Please enter the 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,
));
}
}
然后添加一个路由控制文件
applictaion/controller/GuestbookController.php
复制代码 代码如下:
<?php
class GuestbookController extends Zend_Controller_Action
{
// snipping indexAction()...
public function signAction()
{
$request = $this->getRequest();//获取接受到得信息
// include_once("../application/forms/Guestbook.php"); 手动加载类,只有不能自动载入时,才需要
$form = new Application_Form_Guestbook;//实例化这个方法
if ($this->getRequest()->isPost()) {//如果是POST传递的结果
if ($form->isValid($request->getPost())) {//判断传递是否有效
$comment = new Application_Model_Guestbook($form->getValues());
$mapper = new Application_Model_GuestbookMapper();
$mapper->save($comment);
return $this->_helper->redirector('index');
}
}
$this->view->form = $form;//将表单赋值给试图
}
}
最后添加一个简单的sign视图文件即可:
地址:application/views/scripts/guestbook/sgin.php
复制代码 代码如下:
Please use the form below to sign our guestbook!
<?php
$this->form->setAction($this->url());
echo $this->form;
无为清净楼资源网 Design By www.qnjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
无为清净楼资源网 Design By www.qnjia.com
暂无评论...
更新日志
2024年09月23日
2024年09月23日
- 华少翌.2005-华少翌【中唱艺能】【WAV+CUE】
- 群星《十二女声Ⅱ》[WAV/CUE/分轨][527MB]
- 大自然音乐系列《漫步在山裡》[WAV/CUE/分轨][502.8MB]
- 大自然音乐系列《星光夜语》[WAV/CUE/分轨][453.3MB]
- 史依弘《史依弘交响乐京剧演唱专辑HQ》头版限量编号[WAV+CUE]
- 曼丽2020《女人三十风继续吹》HQCD[WAV+CUE]
- 曼丽2021《女人三十2雾之恋》HQCD[WAV+CUE]
- 隔壁老樊.2019-我曾【好听音乐】【FLAC分轨】
- 高林生.1993-牵挂你的人是我【白天鹅】【WAV+CUE】
- 洪卓立.2012-找个懂我的女孩(国专)【英皇娱乐】【WAV+CUE】
- 曼丽2022《女人三十3晚秋》HQCD[WAV+CUE]
- 曼丽2018《女人三十4冬天》HQCD[WAV+CUE]
- 柏菲-《好歌30年壹》限量开盘母带ORMCD[低速原抓WAV+CUE]
- 大自然音乐系列《水舞》[WAV/CUE/分轨][424.3MB]
- 大自然音乐系列《星光夜语》[WAV/CUE/分轨][453.3MB]