I need a tutorial to read an existing custom table. I have been searching many tutorial but it looks like we have to create setup / install file first. I just want to read all records from my table, like:
SELECT * FROM mytable
The most confusing part for me is in Magento we have 3 models:
- the model
- the collection model
- the resource model
My table name is paketid_booking_result
I want to show it in adminhtml_sales_order_shipment_view
My table has already some records in it.
I have tried to create :
class PaketId_Shipping_Model_Resource_Result_Collection extends Mage_Eav_Model_Entity_Collection_Abstractprotected function _construct() { $this->_init('paketid_shipping/result'); }class PaketId_Shipping_Model_Resource_Result extends Mage_EAV_Model_Entity_Abstractpublic function __construct() { $resource = Mage::getSingleton('core/resource'); $this->setType('paketid_shipping_result'); $this->setConnection( $resource->getConnection('shipping_read'), $resource->getConnection('shipping_write') ); }class PaketId_Shipping_Model_Result extends Mage_Core_Model_Abstractprotected function _construct() { $this->_init('paketid_shipping/result'); //initialized resource model }
Config file config.xml:
<config>
<modules>
<PaketId_Shipping>
<version>1.0</version>
</PaketId_Shipping>
</modules>
<global>
<models>
<paketid_shipping>
<class>PaketId_Shipping_Model</class>
<resourceModel>paketid_shipping_result</resourceModel>
</paketid_shipping>
<paketid_shipping_resource>
<class>PaketId_Shipping_Model_Resource</class>
</paketid_shipping_resource>
<paketid_shipping_resource>
<class>PaketId_Shipping_Model_Resource</class>
<entities>
<result>
<table>paketid_booking_result</table>
</result>
</entities>
</paketid_shipping_resource>
</models>
<helpers>
<paketid_shipping>
<class>PaketId_Shipping_Helper</class>
</paketid_shipping>
</helpers>
<blocks>
<paketid_shipping>
<class>PaketId_Shipping_Block</class>
</paketid_shipping>
</blocks>
<resources>
<shipping_write>
<connection>
<use>core_write</use>
</connection>
</shipping_write>
<shipping_read>
<connection>
<use>core_read</use>
</connection>
</shipping_read>
</resources>
</global>
<adminhtml>
<layout>
<updates>
<paketid_booking>
<file>shipping.xml</file>
</paketid_booking>
</updates>
</layout>
</adminhtml>
<default>
<carriers>
<paketid_shipping>
<active>1</active>
<sallowspecific>1</sallowspecific>
<model>paketid_shipping/carrier</model>
<name>Paket ID Shipping Extension</name>
<price>10.00</price>
<title>Paket ID Shipping Extension</title>
</paketid_shipping>
</carriers>
</default>
</config>
The layout shipping.xml :
<layout version="1.0">
<adminhtml_sales_order_shipment_view>
<reference name="content">
<block type="paketid_booking/adminhtml_sales_order_view_info_booking" name="paketid_booking.order.info.booking.block" template="paketid/shipping.phtml" after="order_history" />
</reference>
</adminhtml_sales_order_shipment_view>
</layout>
The template shipping.phtml :
<?php echo $this->getChildHtml('PaketId_Shipping');?>
<?php $booking = Mage::getModel('paketid_shipping/result')->getCollection();
<?php foreach($bookings as $booking): ?>
<h1><?php echo $booking->getBookingCode() ?></h1>
Those script above produce nothing, I mean my query didn't return anything, and my shipping.phtml not showing. The existing table paketid_booking_result is coming from another extension, I want to show it in admin page for a reason.
I am new in Magento, I really need advice and best practice for my case. Any help would be appreciated. Thanks in advanced.
1 Answer 1
Your resourceModel node is not properly declared in your config.xml
It should match the node that declares the resource models so instead of:
<resourceModel>paketid_shipping_result</resourceModel>
You should have:
<resourceModel>paketid_booking_resource</resourceModel>
Because your resource model declaration is the following:
<paketid_booking_resource>
<class>PaketId_Shipping_Model_Resource</class>
<entities>
<result>
<table>paketid_booking_result</table>
</result>
</entities>
</paketid_booking_resource>
-
thanks for your correction, but my template still not showing, so that I cannot check my query :(may– may2016年09月15日 09:48:37 +00:00Commented Sep 15, 2016 at 9:48
shipping.xmlin yourconfig.xmllayoutafterglobaltag