我只是尝试使用_prepareCollection函数在磁电机中获取两个表的集合。
protected function _prepareCollection()
{
$collection = Mage::getResourceModel('admin/user_collection');
$collection->getSelect()->join( array('table_alias'=>$this->getTable('admin/admin_role')), 'main_table.user_id = table_alias.user_id', array('table_alias.*'));
$this->setCollection($collection);
return parent::_prepareCollection();
}
但它显示语法错误:SQLSTATE[42000]:语法错误或访问冲突:1103 表名 '' 不正确
您可以
先尝试打印 select 语句以查看管理员用户集合表的表别名,然后使用它而不是main_table
为此,请编写以下语句。
echo $collection->getSelect()->__toString();