致命的なエラー:メンバー関数setorder()への呼び出し
-
22-10-2019 - |
質問
プラグインを作成してみると、問題がほとんどありません。
これは私のコードです:
** mibloque.php
class Uniagro_Tpv_Block_Mibloque extends Mage_Core_Block_Template
{
public function methodblock()
{
//return "informations about my block !!" ;
//on initialize la variable
$retour='';
/* we are doing the query to select all elements of the pfay_test table (thanks to our model test/test and we sort them by id_pfay_test */
$collection = Mage::getModel('tpv/tpv')->getCollection()->setOrder('id','asc');
/* then, we check the result of the query and with the function getData() */
foreach($collection as $data)
{
$retour .= $data->getData('banco').' '.$data->getData('codigotienda')
.' '.$data->getData('url').'<br />';
}
//i return a success message to the user thanks to the Session.
Mage::getSingleton('adminhtml/session')->addSuccess('Cool Ca marche !!');
return $retour;
}
}
** config.xml
<?xml version="1.0"?>
<config>
<modules>
<Uniagro_Tpv>
<version>1.0.0</version>
</Uniagro_Tpv>
</modules>
<frontend>
<routers>
<routeurfrontend>
<use>standard</use>
<args>
<module>Uniagro_Tpv</module>
<frontName>pasarela</frontName> <!-- sirve a modo de ruta del modulo [...]/index y va al modulo -->
</args>
</routeurfrontend>
</routers>
<layout>
<updates>
<tpv>
<file>uniagropasarela.xml</file>
</tpv>
</updates>
</layout>
</frontend>
<global>
<blocks>
<tpv>
<class>Uniagro_Tpv_Block</class>
</tpv>
</blocks>
<models>
<tpv>
<class>Uniagro_Tpv_Model</class>
<resourceModel>tpv_mysql4</resourceModel>
</tpv>
<tpv_mysql4>
<class>Uniagro_Tpv_Model_Mysql4</class>
<entities>
<tpv>
<table>uniagro_datosPasarela</table>
</tpv>
</entities>
</tpv_mysql4>
</models>
<resources>
<!-- connection to write -->
<tpv_write>
<connection>
<use>core_write</use>
</connection>
</tpv_write>
<!-- connection to read -->
<tpv_read>
<connection>
<use>core_read</use>
</connection>
</tpv_read>
</resources>
</global>
</config>
**モデル/tpv.php
class Uniagro_Tpv_Model_Tpv extends Mage_Core_Model_Abstract
{
public function _construct()
{
parent::_construct();
$this->_init('tpv/tpv');
}
}
**モデル/mysql4/tpv.php
class Uniagro_Tpv_Mysql4_Tpv extends Mage_Core_Model_Mysql4_Abstract
{
public function _construct()
{
$this->_init('tpv/tpv', 'id');
}
}
私はいくつかの解決策を試しています(たとえば、致命的なエラー:Magentoの非オブジェクトでメンバー関数getCollection()への呼び出し
[1]: 致命的なエラー:Magentoの非オブジェクトでメンバー関数getCollection()への呼び出し )しかし、常に私と同じエラーを送信します「致命的なエラー:メンバー関数setorder()への呼び出し」
そして、私は自分のBDをレビューし、注文する列を持っています(「ID」)
解決
モデルコレクションクラスを追加して、試してみてください
class Uniagro_Tpv_Mysql4_Tpv_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract{
public function _construct(){
$this->_init('tpv/tpv');
}
}
編集 (コメントの結果として):
問題は、間違った名前付き/配置されたクラスでした Uniagro_Tpv_Mysql4_Tpv
に属します Model
エリアがそうでなければなりません Uniagro_Tpv_Model_Mysql4_Tpv
他のヒント
これは機能するはずです。
$collection = Mage::getModel('tpv/tpv')->getCollection();
$collection->getSelect()->order('main_table.id ASC');
所属していません magento.stackexchange