我创建了collection.php
模型并添加了addOrderFilter()
函数,但是当我尝试在我的phtml文件中调用addOrderFilter()
时,它给了我
Fatal error: Call to a member function addOrderFilter() on boolean in [...]\magento\app\design\adminhtml\default\default\template\paketid\shipping.phtml on line 5
这是我的shipping.phtml
:
<?php echo $this->getChildHtml('PaketId_Shipping');?>
<h1>Test custom block</h1>
<?php $order = $this->getOrder()?>
<?php $shipping = Mage::getModel('paketid_shipping/result')->getCollection()->addOrderFilter($order) ?>
<?php if(count($shipping)):
foreach($shipping as $shipping): ?>
<?php echo $this->__('Booking Code') ;?>
<?php echo $shipping->getBookingCode(); ?>
<?php endforeach; ?>
<?php endif; ?>
我的collection.php
型号:
class PaketId_Shipping_Model_Resource_Result_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
protected $order;
protected function _construct()
{
$this->_init('paketid_shipping/result');
}
public function addOrderFilter($order)
{
if ($order instanceof Mage_Sales_Model_Order) {
$order = (int) $order->getId();
}
if (!is_array($order)) {
$order = array($order);
}
$this->getSelect()->where("main_table.order_id IN (?)", $order);
//$this->getSelect()->where("main_table.order_id IN (?)", $order)->order('id DESC');
return $this;
}
令人困惑的部分是,为什么我的phtml不能呈现我的collection
模型?我做错了吗?
答案 0 :(得分:0)
确保magento未在编译模式下运行。
OR
语法Mage::getModel('paketid_shipping/result')->getCollection()
有问题。这不会返回正确的集合对象。尝试调试它是否返回集合对象。
OR
您可以尝试不同的类似语法
Mage::getResourceModel('paketid_shipping/result_collection')->addOrderFilter($order);