Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 带有Magento的GetModel类基于不是主键的mysql字段检索数据_Php_Sql_Magento - Fatal编程技术网

Php 带有Magento的GetModel类基于不是主键的mysql字段检索数据

Php 带有Magento的GetModel类基于不是主键的mysql字段检索数据,php,sql,magento,Php,Sql,Magento,我想更改此代码段以从表中获取一些数据,而不是触发主键(这看起来像load()函数的默认行为),我想触发请求中的另一个字段……我该怎么做 $mytable = Mage::getModel('mytable/mytable')->load($mytable_id)->getData(); thx您可以使用该系列: $mytable = Mage::getModel('mytable/mytable')->getCollection()->addFieldToFilter(

我想更改此代码段以从表中获取一些数据,而不是触发主键(这看起来像load()函数的默认行为),我想触发请求中的另一个字段……我该怎么做

$mytable = Mage::getModel('mytable/mytable')->load($mytable_id)->getData();

thx

您可以使用该系列:

$mytable = Mage::getModel('mytable/mytable')->getCollection()->addFieldToFilter('your_attribute_code', 'your_filter_value'); // here you'll get a collection
否则:

$mytable = Mage::getModel('mytable/mytable')->load('filter_value', 'attribute_code');
如果使用->getCollection(),则可能需要使用->getFirstItem()仅获取第一个项目

$mytable = Mage::getModel('mytable/mytable')->getCollection()->addFieldToFilter('your_attribute_code', 'your_filter_value')->getFirstItem();

Thx,但是您知道如何将sql属性:“LIKE”用于此类代码段(您给我的第一个代码段)?下面是LIKE的示例:$mytable=Mage::getModel('mytable/mytable')->getCollection()->addFieldToFilter('name',array('LIKE'=>'abc%');