zendframework 常用收集

一 配置數據庫.

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 [email protected] 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');

            }

        }



發佈了34 篇原創文章 · 獲贊 14 · 訪問量 7萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章