• <small id='HzlXx'></small><noframes id='HzlXx'>

      <legend id='HzlXx'><style id='HzlXx'><dir id='HzlXx'><q id='HzlXx'></q></dir></style></legend>

        <tfoot id='HzlXx'></tfoot>

        <i id='HzlXx'><tr id='HzlXx'><dt id='HzlXx'><q id='HzlXx'><span id='HzlXx'><b id='HzlXx'><form id='HzlXx'><ins id='HzlXx'></ins><ul id='HzlXx'></ul><sub id='HzlXx'></sub></form><legend id='HzlXx'></legend><bdo id='HzlXx'><pre id='HzlXx'><center id='HzlXx'></center></pre></bdo></b><th id='HzlXx'></th></span></q></dt></tr></i><div id='HzlXx'><tfoot id='HzlXx'></tfoot><dl id='HzlXx'><fieldset id='HzlXx'></fieldset></dl></div>
          <bdo id='HzlXx'></bdo><ul id='HzlXx'></ul>
      1. 在教义中使用列值作为数组索引

        Using column value as array index in doctrine(在教义中使用列值作为数组索引)

        1. <tfoot id='DnWYc'></tfoot>

            <bdo id='DnWYc'></bdo><ul id='DnWYc'></ul>

              <small id='DnWYc'></small><noframes id='DnWYc'>

                <i id='DnWYc'><tr id='DnWYc'><dt id='DnWYc'><q id='DnWYc'><span id='DnWYc'><b id='DnWYc'><form id='DnWYc'><ins id='DnWYc'></ins><ul id='DnWYc'></ul><sub id='DnWYc'></sub></form><legend id='DnWYc'></legend><bdo id='DnWYc'><pre id='DnWYc'><center id='DnWYc'></center></pre></bdo></b><th id='DnWYc'></th></span></q></dt></tr></i><div id='DnWYc'><tfoot id='DnWYc'></tfoot><dl id='DnWYc'><fieldset id='DnWYc'></fieldset></dl></div>
                  <tbody id='DnWYc'></tbody>
                <legend id='DnWYc'><style id='DnWYc'><dir id='DnWYc'><q id='DnWYc'></q></dir></style></legend>

                  本文介绍了在教义中使用列值作为数组索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在使用学说 2.1 为 settings 表创建模型:

                  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 
                  

                  假设我有很多不同类别的设置.为了获得特定类别的所有设置,我执行以下操作:

                  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);
                  

                  此时一切正常.嗯.. 64,000 美元的问题是:是否存在允许我读取如下结果的数据访问替代方案?

                  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.

                  导入查询类(并非总是可选的):

                  import the Query class (no always optional):

                  use DoctrineORMQuery;
                  

                  创建查询:

                  $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');
                  

                  设置隐藏模式以使用只读数组

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

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

                  显示值:

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

                  查询生成器

                  使用 QueryBuilder 对象,您可以在 from 语句中设置索引:

                  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();
                  

                  然后,您可以通过以下方式访问该对象:

                  Then, you can access the object as:

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

                  这篇关于在教义中使用列值作为数组索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                  PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                  mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                  Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                  Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                  Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)

                  <i id='qg44y'><tr id='qg44y'><dt id='qg44y'><q id='qg44y'><span id='qg44y'><b id='qg44y'><form id='qg44y'><ins id='qg44y'></ins><ul id='qg44y'></ul><sub id='qg44y'></sub></form><legend id='qg44y'></legend><bdo id='qg44y'><pre id='qg44y'><center id='qg44y'></center></pre></bdo></b><th id='qg44y'></th></span></q></dt></tr></i><div id='qg44y'><tfoot id='qg44y'></tfoot><dl id='qg44y'><fieldset id='qg44y'></fieldset></dl></div>
                  <tfoot id='qg44y'></tfoot>

                        1. <small id='qg44y'></small><noframes id='qg44y'>

                          <legend id='qg44y'><style id='qg44y'><dir id='qg44y'><q id='qg44y'></q></dir></style></legend>
                            <bdo id='qg44y'></bdo><ul id='qg44y'></ul>
                              <tbody id='qg44y'></tbody>