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

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

        <legend id='hYjD4'><style id='hYjD4'><dir id='hYjD4'><q id='hYjD4'></q></dir></style></legend>
          <bdo id='hYjD4'></bdo><ul id='hYjD4'></ul>
        <tfoot id='hYjD4'></tfoot>

      1. 如何使用 symfony 在管理面板中对自己的列进行排序?

        How to sort own columns in admin panel with symfony?(如何使用 symfony 在管理面板中对自己的列进行排序?)

          <tbody id='iMMJg'></tbody>

      2. <legend id='iMMJg'><style id='iMMJg'><dir id='iMMJg'><q id='iMMJg'></q></dir></style></legend>

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

          • <bdo id='iMMJg'></bdo><ul id='iMMJg'></ul>
            <tfoot id='iMMJg'></tfoot>

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

                1. 本文介绍了如何使用 symfony 在管理面板中对自己的列进行排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  M schema.yml:

                  M schema.yml:

                  News:
                    columns:
                      title:
                        type: string(50)
                      category_id:
                        type: integer(4)
                    relations:
                      Category:
                        local: category_id
                        foreign: category_id
                        type: one
                  
                  Category:
                    columns:
                      category_name:
                        type: string(50)
                  
                  generator:
                    class: sfDoctrineGenerator
                    param:
                      model_class:           News
                      theme:                 admin
                      non_verbose_templates: true
                      with_show:             false
                      singular:              ~
                      plural:                ~
                      route_prefix:          news
                      with_doctrine_route:   true
                      actions_base_class:    sfActions
                  
                      config:
                        actions: ~
                        fields:  ~
                        list:
                          display: [news_id, title, category_name]
                        filter:
                          display: [news_id, title, category_id]
                        form:    ~
                        edit:    ~
                        new:     ~
                  

                  在 news.class 中:

                  In news.class:

                  public function getCategoryName()
                  {
                    return $this->getCategories()->getCategoryName();
                  }
                  

                  这可行,但我无法对该字段进行排序.我可以按 id、title、category_id 排序,但不能按 category_name 排序.如何按此自定义列排序?

                  This works, but I can't sort this field. I can sort by id, title, category_id, but not by category_name. How can I sort by this custom column?

                  推荐答案

                  这些是达到所需结果的步骤.

                  These are the steps to achieve the required result.

                  1. 在你的 generator.yml 中定义一个表格方法

                  1. Define a table method in your generator.yml

                  config:
                    actions: ~
                    fields:  ~
                    list:
                      display: [news_id, title, category_name]
                      table_method: doSelectJoinCategory
                  

                2. 将 doSelectJoinCateory 添加到您的 NewsTable.class.php

                3. Add doSelectJoinCateory to your NewsTable.class.php

                  class NewsTable extends Doctrine_Table
                  {
                    ...  
                    public static function doSelectJoinCategory($query)
                    {
                      return $query->select('r.*, c.cateogry_name')
                        ->leftJoin('r.Category c');
                    }
                  }
                  

                4. 你需要覆盖你的actions.class.php中的排序查询

                5. You need to override the sort query in your actions.class.php

                  class newsActions extends autoNewsActions
                  {
                    ...
                    protected function addSortQuery($query)
                    {
                      if (array(null, null) == ($sort = $this->getSort()))
                      {
                        return;
                      }
                  
                      if (!in_array(strtolower($sort[1]), array('asc', 'desc')))
                      {
                        $sort[1] = 'asc';
                      }
                  
                      switch ($sort[0]) {
                        case 'category_name':
                        $sort[0] = 'c.category_name';
                        break;
                      }
                  
                    $query->addOrderBy($sort[0] . ' ' . $sort[1]);
                  }
                  

                6. 默认生成器主题将要求您覆盖 actions.class.php 中的 isValidSortColumn

                7. The default generator theme will require that you override the isValidSortColumn in actions.class.php

                  protected function isValidSortColumn($column)
                  {
                    return Doctrine_Core::getTable(‘Payment’)->hasColumn($column) || $column == ‘cateogry_name’;
                  }
                  

                8. 您需要覆盖生成器主题以显示排序链接和图标,因为它要求排序字段是真正的数据库映射字段.编辑你的 symfony_dir/lib/plugins/sfDoctrinePlugin/data/generator/sfDoctrineModule/admin/template/templates/_list_th_tabular.php :

                9. You will need to override the generator theme to display sort link and icons as it requires the sort field to be real database mapped field. edit your symfony_dir/lib/plugins/sfDoctrinePlugin/data/generator/sfDoctrineModule/admin/template/templates/_list_th_tabular.php :

                  改变这一行

                  <?php if ($field->isReal()): ?>
                  

                  对此:

                  <?php if ($field->isReal() || $field->getConfig('sortBy')): ?>
                  

                  希望对你有帮助

                  这篇关于如何使用 symfony 在管理面板中对自己的列进行排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  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 的问题)
                  1. <tfoot id='SOTPL'></tfoot>

                      <legend id='SOTPL'><style id='SOTPL'><dir id='SOTPL'><q id='SOTPL'></q></dir></style></legend>
                    1. <small id='SOTPL'></small><noframes id='SOTPL'>

                        • <bdo id='SOTPL'></bdo><ul id='SOTPL'></ul>

                            <tbody id='SOTPL'></tbody>

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