多多色-多人伦交性欧美在线观看-多人伦精品一区二区三区视频-多色视频-免费黄色视屏网站-免费黄色在线

國內最全IT社區平臺 聯系我們 | 收藏本站
阿里云優惠2
您當前位置:首頁 > php框架 > ZendFramework > Zend Framework教程-Zend_Db-數據庫操作6-Zend_Db_Table_Definition翻譯

Zend Framework教程-Zend_Db-數據庫操作6-Zend_Db_Table_Definition翻譯

來源:程序員人生   發布時間:2013-11-14 02:02:44 閱讀次數:4427次

Introduction 簡介

Zend_Db_Table_Definition is a class that can be used to describe the relationships and configuration options that should be used when Zend_Db_Table is used via concrete instantiation.

Zend_Db_Table_Definition  用于定義關聯關系和對實例化Zend_Db_Table的相關選項配置的類。

Basic Usage

For all of the same options that are available when configuring an extendedZend_Db_Table_Abstract class, those options are also available when describing a definition file. 

 所有繼承實現Zend_Db_Table_Abstract 類的配置選項,都是可以使用定義描述文件的。

This definition file should be passed to the class at instantiation time so that it can know the full definition of all tables in said definition.

通過在實例化時,將表的定義文件傳遞給類。


Below is a definition that will describe the table names and relationships between table objects. 


下面是表名和表對象之間的關聯關系的定義。


Note: if 'name' is left out of the definition, it will be taken as the key of the defined table (an example of this is in the 'genre' section in the example below.)

注:如果“name”的定義被省略了,將采用表定義的key值(例如下面的“genre”部分)。

Example #1 Describing the Definition of a Database Data Model  數據庫的數據模型定義描述


$definition = new Zend_Db_Table_Definition(array(    'author' => array(        'name' => 'author',        'dependentTables' => array('book')        ),    'book' => array(        'name' => 'book',        'referenceMap' => array(            'author' => array(                'columns' => 'author_id',                'refTableClass' => 'author',                'refColumns' => 'id'                )            )        ),    'genre' => null,    'book_to_genre' => array(        'referenceMap' => array(            'book' => array(                'columns' => 'book_id',                'refTableClass' => 'book',                'refColumns' => 'id'                ),            'genre' => array(                'columns' => 'genre_id',                'refTableClass' => 'genre',                'refColumns' => 'id'                )            )        )    ));



As you can see, the same options you'd generally see inside of an extended Zend_Db_Table_Abstract class are documented in this array as well. 


正如你看到的,繼承實現Zend_Db_Table_Abstract類時相同的選項,也要在這個數組中定義。


When passed into  Zend_Db_Table constructor, this definition ispersisted to any tables it will need to create in order to return the proper rows.

當傳入  Zend_Db_Table 構造函數時, 這個定義會被持久化到所有表中。它必須被創建目的是為了返回對應的行 。

Below is an example of the primary table instantiation as well as thefindDependentRowset() and findManyToManyRowset() calls that will correspond to the data model described above:

下面是通過上面定義的主表實例化的例子,然后調用 findDependentRowset()和 findManyToManyRowset()方法:


Example #2 Interacting with the described definition 描述定義使用

   

$authorTable = new Zend_Db_Table('author', $definition);$authors = $authorTable->fetchAll(); foreach ($authors as $author) {    echo $author->id       . ': '       . $author->first_name       . ' '       . $author->last_name       . PHP_EOL;    $books = $author->findDependentRowset('book');    foreach ($books as $book) {        echo '    Book: ' . $book->title . PHP_EOL;        $genreOutputArray = array();        $genres = $book->findManyToManyRowset('genre', 'book_to_genre');        foreach ($genres as $genreRow) {            $genreOutputArray[] = $genreRow->name;        }        echo '        Genre: ' . implode(', ', $genreOutputArray) . PHP_EOL;    }}


Advanced Usage高級用法


Sometimes you want to use both paradigms for defining and using the table gateway: both by extension and concrete instantiation.To do this simply leave out any table configurations out of the definition. 

有時可能會同時使用Zend_Db_Table和 Zend_Db_Table_Definition。要做到這一點,只需實現所有表的定義,即可。

This will allow Zend_Db_Table to look for the actual refered class instead of the definition key.

允許采用Zend_Db_Table的具體類代替定義的KEY

Building on the example above, we will allow for one of the table configurations to be aZend_Db_Table_Abstract extended class, while keeping the rest of the tables as part of the definition. 

基于上面的例子, 我們可以配置其中一個 實例化Zend_Db_Table_Abstract 的類,   而其它的表保持原有定義。

We will also show how one would interact with this new definition.

以下是具體的定義。


Example #3 Interacting A Mixed Use Zend_Db_Table Definition 混合使用Zend_Db_Table定義


class MyBook extends Zend_Db_Table_Abstract{    protected $_name = 'book';    protected $_referenceMap = array(        'author' => array(            'columns' => 'author_id',            'refTableClass' => 'author',            'refColumns' => 'id'            )        );} $definition = new Zend_Db_Table_Definition(array(    'author' => array(        'name' => 'author',        'dependentTables' => array('MyBook')        ),    'genre' => null,    'book_to_genre' => array(        'referenceMap' => array(            'book' => array(                'columns' => 'book_id',                'refTableClass' => 'MyBook',                'refColumns' => 'id'                ),            'genre' => array(                'columns' => 'genre_id',                'refTableClass' => 'genre',                'refColumns' => 'id'                )            )        )    )); $authorTable = new Zend_Db_Table('author', $definition);$authors = $authorTable->fetchAll(); foreach ($authors as $author) {    echo $author->id       . ': '       . $author->first_name       . ' '       . $author->last_name       . PHP_EOL;    $books = $author->findDependentRowset(new MyBook());    foreach ($books as $book) {        echo '    Book: ' . $book->title . PHP_EOL;        $genreOutputArray = array();        $genres = $book->findManyToManyRowset('genre', 'book_to_genre');        foreach ($genres as $genreRow) {            $genreOutputArray[] = $genreRow->name;        }        echo '        Genre: ' . implode(', ', $genreOutputArray) . PHP_EOL;    }}





-----------

對譯文與原文在含義上的差異而造成的誤解不承擔任何責任。僅供參考。 




生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關閉
程序員人生
主站蜘蛛池模板: 欧美一区二区视频在线观看 | 亚洲三级色 | 亚洲一级生活片 | jizz免费观看视频 | 免费区欧美一级毛片精品 | 波多野结衣在线观看一区 | 福利国产精品 | 午夜在线免费视频 | 亚洲人成网站在线观看播放 | 日本免费一区二区三区看片 | 亚洲成a人片在线观看精品 亚洲成a人片在线观看尤物 | 真人肉体一级毛片 | 毛片免费网 | 亚洲综合站| 日韩拍拍拍 | 欧美极品尤物在线播放一级 | 欧美精品高清 | 黑人又大又粗又长又深受不了 | 中文字幕一区精品欧美 | 亚洲图片综合网 | free asian xxxxx黑人 | 亚洲精品久久久久午夜三 | 日韩欧美一中文字幕不卡 | 日本欧美午夜 | 国产日韩一区在线精品欧美玲 | 国产高清精品91在线 | 亚洲另类精品xxxx人妖 | 日本xxxwww在线观看免费 | 欧美黑粗特黄午夜大片 | 国产精品毛片在线大全 | 在线不卡免费视频 | 欧美高清一级啪啪毛片 | 欧美国产另类 | 在线看片日韩 | 亚洲欧美日韩中文综合v日本 | 在线看黄网址 | 亚洲精品色综合区 | ww在线观视频免费观看 | 午夜一区二区三区 | 免费国产成人α片 | 国产成人精品日本亚洲网站 |