简体   繁体   English

修改资源模型中的函数以在Magento中进行“等于”搜索

[英]Modify function in resource model to do do an 'equals' search in Magento

I have the following function in my Resource Collection which is as follows: 我的资源集合中具有以下功能,如下所示:

public function searchByNameOnly($term)
{
    $this->addFieldToFilter(array('organisation_name'),array(
        array('like' => $term.'%'),
        array('like' => $term.'%')
    ));
    return $this;
}

I want to amend this so it isn't using the LIKE but rather an equals, so in a sense the SQL equivalent would look like this: 我想对此进行修改,因此它不使用LIKE,而是使用等号,因此从某种意义上讲,SQL等效项如下所示:

SELECT * FROM table WHERE organisation_name = 'ACME Inc';

How should I amend the function above to do this? 我应该如何修改上面的功能来做到这一点?

Use 'eq' instead of 'like': 使用“ eq”代替“ like”:

$this->addFieldToFilter(array('organisation_name'),array(
    array('eq' => $term.'%'),
    array('eq' => $term.'%')
));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM