一 配置数据库.
resources.db.adapter = "pdo_mysql"
resources.db.params.host = "localhost"
resources.db.params.username = "root"
resources.db.params.password = "admin"
resources.db.params.dbname = "test"
resources.db.params.prefix = "tt_"
resources.db.isDefaultTableAdapter = true
resources.db.params.driver_options.1002 = "SET NAMES UTF8;"
二 禁用layout.
$this->_helper->layout()->disableLayout();
三 禁用默认视图.
$controller = Zend_Controller_Front::getInstance();
$controller->setParam('noViewRenderer',true);
四 写一个view 的helper
<?php
// filename is /applications/views/helpers/Pr.php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_View
* @subpackage Helper
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Abstract.php 23775 2011-03-01 17:25:24Z ralph $
*/
/**
* @see Zend_View_Helper_Interface
*/
/**
* @category Zend
* @package Zend_View
* @subpackage Helper
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_View_Helper_pr implements Zend_View_Helper_Interface
{
/**
* 预格式化输出数组
*
* @param string $array
* @return no return.
*/
function pr($array,$title = 'DEBUGINFO')
{
echo "<fieldset style=\"border: 1px solid rgb(0, 153, 0); margin: 20px 0pt; padding: 6px 10px 10px; background-color: rgb(238, 238, 238);\">
<legend style=\"color: rgb(0, 153, 0);\">$title</legend>";
echo "<div style = 'font-size:14px; color:#000; border:1px solid #666; background:#ccc; padding:5px;'>";
print("<pre>");
print_r($array);
print("</pre>");
echo "<div>";
echo "</fieldset>";
}
/**
* View object
*
* @var Zend_View_Interface
*/
public $view = null;
/**
* Set the View object
*
* @param Zend_View_Interface $view
* @return Zend_View_Helper_Abstract
*/
public function setView(Zend_View_Interface $view)
{
$this->view = $view;
return $this;
}
/**
* Strategy pattern: currently unutilized
*
* @return void
*/
public function direct()
{
}
}
//how to use it .
//控制器下
$this->view->Pr($obj,'promptInfo');
//视图下
$this->Pr($obj,'promptInfo');
接收表单数据,并保存。
//感觉zend_form 很垃圾,并不好用。
if ($this->getRequest()->isPost()) {
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');
}
}