过滤一个新的customfield Phreeze

时间:2013-11-08 09:57:57

标签: search filter phreeze

我正在使用Phreeze来创建应用程序。 一切顺利,但当我想在模板中过滤自定义字段(tagtypeName)时,它不会这样做。

我在model.js中有模型:

model.TagModel = Backbone.Model.extend({
    urlRoot: 'api/tag',
    idAttribute: 'id',
    id: '',
    name: '',
    type: '',
    TagtypeName: '',
    baja: '',
    defaults: {
        'id': null,
        'name': '',
        'type': '',
        'baja': ''
    }
});

我的标准是TagCriteria.php:

public function GetFieldFromProp($propname)
    {
        switch($propname)
        {
            case 'TagtypeName':
                return 'tagtype.id';
            case 'Id':
                return 'tag.id';    
            case 'Name':
                return 'tag.name';
            case 'Type':
                return 'tag.type';
            case 'Baja':
                return 'tag.baja';  
            default:
                return parent::GetFieldFromProp($propname);
                //throw new Exception('Unable to locate the database column for the property: ' . $propname);
        }
    }

我的记者是: public $ Id;     public $ Name;     public $ Type;     公共$ Baja;     public $ TagtypeName;

/*
* GetCustomQuery returns a fully formed SQL statement.  The result columns
* must match with the properties of this reporter object.
*
* @see Reporter::GetCustomQuery
* @param Criteria $criteria
* @return string SQL statement
*/
static function GetCustomQuery($criteria)
{
    $sql = "select
        `tagtype`.`name` as TagtypeName
        ,`tag`.`id` as Id
        ,`tag`.`name` as Name
        ,`tag`.`type` as Type
        ,`tag`.`baja` as Baja
    from `tag`
    inner join `tagtype` on `tagtype`.`id`=`tag`.`type`";

    // the criteria can be used or you can write your own custom logic.
    // be sure to escape any user input with $criteria->Escape()
    $sql .= $criteria->GetWhere();
    $sql .= $criteria->GetOrder();

    return $sql;
}

视图有:

        <script type="text/template" id="tagCollectionTemplate">
            <table class="collection table table-bordered table-hover">
            <thead>
                <tr>
                    <th id="header_Id">Id<% if (page.orderBy == 'Id') { %> <i class='icon-arrow-<%= page.orderDesc ? 'up' : 'down' %>' /><% } %></th>
                    <th id="header_Name">Name<% if (page.orderBy == 'Name') { %> <i class='icon-arrow-<%= page.orderDesc ? 'up' : 'down' %>' /><% } %></th>
                    <!--<th id="header_Type">Type<% if (page.orderBy == 'Type') { %> <i class='icon-arrow-<%= page.orderDesc ? 'up' : 'down' %>' /><% } %></th>-->
                    <th id="header_Type">Type<% if (page.orderBy == 'TagtypeName') { %> <i class='icon-arrow-<%= page.orderDesc ? 'up' : 'down' %>' /><% } %></th>
                    <th id="header_Baja">Baja<% if (page.orderBy == 'Baja') { %> <i class='icon-arrow-<%= page.orderDesc ? 'up' : 'down' %>' /><% } %></th>
                </tr>
            </thead>
            <tbody>
            <% items.each(function(item) { %>
                <tr id="<%= _.escape(item.get('id')) %>">
                    <td><%= _.escape(item.get('id') || '') %></td>
                    <td><%= _.escape(item.get('name') || '') %></td>
                    <!--<td><%= _.escape(item.get('type') || '') %></td>-->
                    <td><%= _.escape(item.get('tagtypeName') || '') %></td>
                    <td><%= _.escape(item.get('baja') || '') %></td>
                </tr>
            <% }); %>
            </tbody>
            </table>

            <%=  view.getPaginationHtml(page) %>
        </script>

在我的控制器中我已将标签更改为我的记者:

$tags = $this->Phreezer->Query('TagReporter',$criteria)->GetDataPage($page, $pagesize);

因此,当我转到页面时,我看到的是表而不是类型ID,它根据需要从我的客户查询中获得了类型的名称 enter image description here

但是当我过滤时,没有找到新自定义字段的数据: enter image description here

有谁知道如何处理这个问题?

1 个答案:

答案 0 :(得分:2)

问题在于我必须更改记者数量并设置内部联接:

static function GetCustomCountQuery($criteria)
    {
        $sql = "select count(1) as counter from `tag`
        inner join `tagtype` on `tagtype`.`id`=`tag`.`type`";

        // the criteria can be used or you can write your own custom logic.
        // be sure to escape any user input with $criteria->Escape()
        $sql .= $criteria->GetWhere();

        return $sql;
    }

这样做对我来说没问题!