久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

Zend 框架中的模型

Models in the Zend Framework(Zend 框架中的模型)
本文介紹了Zend 框架中的模型的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

您在 Zend 框架中實現(xiàn)模型的方式有哪些?

What are some of the ways you have implemented models in the Zend Framework?

我已經(jīng)看到了基本的 class User extends Zend_Db_Table_Abstract 然后在你的控制器中調(diào)用它:

I have seen the basic class User extends Zend_Db_Table_Abstract and then putting calls to that in your controllers:

$foo = 新用戶;

$foo->fetchAll()

但是更復雜的用途呢?文檔的快速入門部分提供了這樣一個示例,但我仍然覺得我沒有得到 Zend Framework 中模型的最佳使用"示例.有什么有趣的實現(xiàn)嗎?

but what about more sophisticated uses? The Quickstart section of the documentation offers such an example but I still feel like I'm not getting a "best use" example for models in Zend Framework. Any interesting implementations out there?

我應該澄清(回應 CMS 的評論)...我知道做更復雜的選擇.我對模型概念的整體方法和其他人如何實現(xiàn)它們的具體示例感興趣(基本上,手冊遺漏的內(nèi)容以及基本操作方法所掩蓋的內(nèi)容)

I should clarify (in response to CMS's comment)... I know about doing more complicated selects. I was interested in overall approaches to the Model concept and concrete examples of how others have implemented them (basically, the stuff the manual leaves out and the stuff that basic how-to's gloss over)

推薦答案

我個人對 Zend_Db_Table_AbstractZend_Db_Table_Row_Abstract 進行了子類化.我的代碼和你的代碼之間的主要區(qū)別在于,明確地將 Zend_Db_Table_Abstract 的子類視為表",將 Zend_Db_Table_Row_Abstract 的子類視為行".我很少在控制器中看到直接調(diào)用選擇對象、SQL 或內(nèi)置 ZF 數(shù)據(jù)庫方法.我嘗試隱藏請求特定記錄以調(diào)用 Zend_Db_Table_Abstract 后面的邏輯,如下所示:

I personally subclass both Zend_Db_Table_Abstract and Zend_Db_Table_Row_Abstract. The main difference between my code and yours is that explicitly treat the subclass of Zend_Db_Table_Abstract as a "table" and Zend_Db_Table_Row_Abstract as "row". Very rarely do I see direct calls to select objects, SQL, or the built in ZF database methods in my controllers. I try to hide the logic of requesting specific records to calls for behind Zend_Db_Table_Abstract like so:

class Users extends Zend_Db_Table_Abstract {

    protected $_name = 'users';

    protected $_rowClass = 'User'; // <== THIS IS REALLY HELPFUL

    public function getById($id) {
        // RETURNS ONE INSTANCE OF 'User'
    }

    public function getActiveUsers() {
        // RETURNS MULTIPLE 'User' OBJECTS            
    }

}

class User extends Zend_Db_Table_Row_Abstract {

    public function setPassword() {
        // SET THE PASSWORD FOR A SINGLE ROW
    }

}

/* CONTROLLER */
public function setPasswordAction() {

    /* GET YOUR PARAMS */

    $users = new Users();

    $user = $users->getById($id);

    $user->setPassword($password);

    $user->save();
}

有很多方法可以解決這個問題.不要認為這是唯一的,但我嘗試遵循 ZF 的設(shè)計意圖.(這里有更多我的關(guān)于這個主題的想法和鏈接.)這種方法確實有點類很重,但我覺得它讓控制器專注于處理輸入和與視圖協(xié)調(diào);讓模型去做特定于應用程序的工作.

There are numerous ways to approach this. Don't think this is the only one, but I try to follow the intent of the ZF's design. (Here are more of my thoughts and links on the subject.) This approach does get a little class heavy, but I feel it keeps the controllers focused on handling input and coordinating with the view; leaving the model to do the application specific work.

這篇關(guān)于Zend 框架中的模型的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Action View Helper in Zend - Work around?(Zend 中的動作視圖助手 - 解決方法?)
Is this a good way to match URI to class/method in PHP for MVC(這是將 URI 與 PHP 中用于 MVC 的類/方法匹配的好方法嗎)
Where do I save partial (views) in Zend Framework, to be accessible for all Views in my App?(我在哪里保存 Zend Framework 中的部分(視圖),以便我的應用程序中的所有視圖都可以訪問?) - IT屋-程序員軟件開發(fā)技術(shù)
Having a single entry point to a website. Bad? Good? Non-issue?(有一個網(wǎng)站的單一入口點.壞的?好的?沒問題?)
Is MVC + Service Layer common in zend or PHP?(MVC + 服務層在 Zend 或 PHP 中常見嗎?)
Hello World example in MVC approach to PHP(PHP MVC 方法中的 Hello World 示例)
主站蜘蛛池模板: 亚洲欧洲一区 | 香蕉视频久久久 | 日韩精品久久一区二区三区 | 欧美成人免费在线视频 | 精品无码久久久久久国产 | 精品美女在线观看视频在线观看 | 国产免费一区二区 | 欧美日韩中文在线观看 | 国产视频福利一区 | 欧美亚洲国产精品 | 国产精品一区二区三 | 国产精品www| 欧美精品在线免费 | www.亚洲.com | 国产精品自产av一区二区三区 | 久久亚洲国产精品日日av夜夜 | 亚洲精品aⅴ | 亚洲狠狠爱一区二区三区 | 久久99久久99精品免视看婷婷 | 久久香蕉精品视频 | 国产色婷婷精品综合在线手机播放 | 久久久久久黄 | 精品影院 | 精品国产欧美一区二区 | 中文字幕高清在线 | 色精品| 欧美综合国产精品久久丁香 | 高清色视频 | 完全免费av在线 | 中文字幕不卡一区 | 久久久久久久久99 | 精品毛片视频 | 亚洲欧美一区二区三区在线 | 国产免费av网 | www.黄色在线观看 | www日本高清视频 | 超碰伊人久久 | 免费日韩av| 欧美日本一区 | 国产福利精品一区 | 日一区二区|