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

Zend 框架中的模型

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

問題描述

您在 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()

但是更復(fù)雜的用途呢?文檔的快速入門部分提供了這樣一個示例,但我仍然覺得我沒有得到 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?

我應(yīng)該澄清(回應(yīng) CMS 的評論)...我知道做更復(fù)雜的選擇.我對模型概念的整體方法和其他人如何實現(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 進(jìn)行了子類化.我的代碼和你的代碼之間的主要區(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();
}

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

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 中的部分(視圖),以便我的應(yīng)用程序中的所有視圖都可以訪問?) - 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 + 服務(wù)層在 Zend 或 PHP 中常見嗎?)
Hello World example in MVC approach to PHP(PHP MVC 方法中的 Hello World 示例)
主站蜘蛛池模板: 99综合| 亚洲免费网址 | 久久久久久久国产精品视频 | 欧美日韩精品综合 | 91视频电影 | 亚洲精品久久久久久国产精华液 | 国产精品日产欧美久久久久 | 精品久久久久久久久久久久 | 91天堂| 一区二区三区欧美 | 99亚洲精品 | 日韩伦理一区二区三区 | av午夜电影| 水蜜桃久久夜色精品一区 | 99re国产| 拍真实国产伦偷精品 | 亚洲精品视频观看 | 精品国产欧美一区二区三区成人 | 久久综合99 | 成人午夜精品 | 成人依人 | 99久久精品免费看国产高清 | 国产精品成人一区二区 | 怡红院成人在线视频 | 粉嫩av久久一区二区三区 | 精品国产乱码久久久久久闺蜜 | 一区二区三区久久 | 精品视频一区二区三区在线观看 | 色播视频在线观看 | 日本一区二区三区四区 | 国产91在线观看 | 一级黄色毛片子 | 免费成人av网站 | 日韩男人天堂 | 日批日韩在线观看 | 操操网站 | 亚洲精品在线视频 | 国产精品欧美一区二区三区不卡 | 亚洲精品视频在线看 | 97人人干 | 免费一区 |