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

在學(xué)說(shuō)中使用列值作為數(shù)組索引

Using column value as array index in doctrine(在學(xué)說(shuō)中使用列值作為數(shù)組索引)
本文介紹了在學(xué)說(shuō)中使用列值作為數(shù)組索引的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

我正在使用doctrine 2.1來(lái)為settings表創(chuàng)建一個(gè)模型:

I am using doctrine 2.1 in order to create a model for settings table:

id |  arg  |  value  |  category
1  |  name |  foo    |  general_settings 
2  |  desc |  bar    |  general_settings 

假設(shè)我有很多不同類別的設(shè)置.為了獲得特定類別的所有設(shè)置,我執(zhí)行以下操作:

Suppose that I have a lot of setting for different categories. In order to get all the setting for a specific category I do something like this:

$q = Doctrine_Query::create()
    ->from('Setting p')
    ->where('p.category = ?', $category_name);

此時(shí)一切正常.嗯.. 64,000 美元的問(wèn)題是:是否存在允許我讀取如下結(jié)果的數(shù)據(jù)訪問(wèn)替代方案?

Everything works fine at this point. Well.. the question of $64,000 is: Do exist a data access alternative that allow me to read the result as below?

$resultSet = $q->execute(); 

//the magic here could be use the -arg- column as index
$requested_setting = $resulSet['name']  

//print the setting value
echo $requested_setting['value'];  //should prints "foo"

//another way
echo $resulSet['desc']['value']; //should prints "bar"

推薦答案

我明白了:這里的訣竅是使用 INDEX BY 詞.

I got it: the trick here is use the INDEX BY word.

導(dǎo)入 Query 類(并非總是可選的):

import the Query class (no always optional):

use DoctrineORMQuery;

創(chuàng)建查詢:

$query = $this->data->em->createQuery('
    SELECT s 
    FROM modelsSetting s 
    INDEX BY s.arg //to set array custom key
    WHERE s.category = :category');
$query->setParameter('category', 'general');

設(shè)置隱藏模式以使用只讀數(shù)組

set the hidration mode in order to work with read-only arrays

$settings = $query->getResult(Query::HYDRATE_ARRAY); 

顯示值:

echo $settings['desc']['value'];  // prints "bar"

查詢構(gòu)建器

使用 QueryBuilder 對(duì)象,您可以在 from 語(yǔ)句中設(shè)置索引:

QueryBuilder

With the QueryBuilder object you can set the index at the from statement:

$qb = $em->createQueryBuilder();
$qb->select('s');
$qb->from('modelsSettings', 's', 's.arg');  // here the magic
$result = $qb->getQuery()->getResult();

然后,您可以通過(guò)以下方式訪問(wèn)該對(duì)象:

Then, you can access the object as:

$description = $result['desc'];
$value = $description->getValue();

這篇關(guān)于在學(xué)說(shuō)中使用列值作為數(shù)組索引的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

Joining 2 tables in SELECT(MYSQL/PHP)(在 SELECT(MYSQL/PHP) 中加入 2 個(gè)表)
How to make lt;option selected=quot;selectedquot;gt; set by MySQL and PHP?(如何使lt;option selected=“selectedgt;由 MySQL 和 PHP 設(shè)置?)
Auto populate a select box using an array in PHP(使用 PHP 中的數(shù)組自動(dòng)填充選擇框)
PHP SQL SELECT where like search item with multiple words(PHP SQL SELECT where like search item with multiple words)
json_encode produce JSON_ERROR_UTF8 from MSSQL-SELECT(json_encode 從 MSSQL-SELECT 產(chǎn)生 JSON_ERROR_UTF8)
MySQL ORDER BY rand(), name ASC(MySQL ORDER BY rand(),名稱 ASC)
主站蜘蛛池模板: 噜久寡妇噜噜久久寡妇 | 久久首页| 国产成人午夜精品影院游乐网 | 在线观看国产视频 | 91av在线看 | 91久久久久久久久久久 | www.v888av.com| 中文字幕一区在线观看视频 | 日韩欧美中文字幕在线观看 | 99久久精品国产毛片 | 黄色大片免费网站 | www.亚洲| 中日字幕大片在线播放 | 精品一区二区久久久久久久网站 | 四色永久| 一二三四在线视频观看社区 | 国产精品成人一区二区三区夜夜夜 | 国产精品精品 | 欧美日韩亚洲一区 | 亚洲欧美日韩精品 | 午夜日韩 | 国产一区二区 | 欧美在线色视频 | 精品成人在线观看 | 国产精品综合一区二区 | 精品欧美乱码久久久久久1区2区 | 国产激情视频在线免费观看 | 在线视频一区二区 | 欧美亚州综合 | 男女啪啪网址 | 黄色网址在线免费观看 | 欧美成人精品一区二区三区 | 日韩一区二区三区在线 | 国产成人精品一区二区三区网站观看 | 国产精品99久久久久久久vr | 亚洲一二三区免费 | 日本一区精品 | 99re热精品视频国产免费 | 亚洲精视频 | 午夜久久久久久久久久一区二区 | 九九九视频精品 |