[英]How to call custom Module/Model class in Magento
我必須在billing.phtml中調用自定義模塊類,該類在結帳頁面上顯示了額外的字段。
但是我遇到了PHP Fatal error: Call to a member function getAllOptions() on a non-object
下面是我的代碼-
文件名-Business.php
文件路徑- /var/www/html/app/code/community/Partsimple/CustomFields/Model/Primarybusiness
class Partsimple_CustomFields_Model_Primarybusiness_Business extends Mage_Eav_Model_Entity_Attribute_Source_Table
{
public function getAllOptions()
{
if (!$this->_options) {
$this->_options[] = array(
'value' => '',
'label' => 'Please Select Primary Business'
);
$this->_options[] = array(
'value' => 1,
'label' => 'End Consumer / DIY'
);
$this->_options[] = array(
'value' => 2,
'label' => 'Service Technician'
);
$this->_options[] = array(
'value' => 3,
'label' => 'Other Professional'
);
// $this->_options = Mage::getResourceModel('directory/region_collection')->load()->toOptionArray();
}
return $this->_options;
}
}
**文件名-** config.xml ****
<config>
<modules>
<Partsimple_CustomFields>
<version>1.0.1</version>
</Partsimple_CustomFields>
</modules>
<global>
<models>
<Partsimple_CustomFields>
<class>Partsimple_CustomFields_Model</class>
</Partsimple_CustomFields>
</models>
<fieldsets>
<customer_account>
<vendor_account>
<create>1</create>
<update>1</update>
</vendor_account>
</customer_account>
<customer_address>
<vendor_account>
<to_quote_address>*</to_quote_address>
</vendor_account>
<primary_business>
<to_quote_address>*</to_quote_address>
<primary_business>
</customer_address>
<sales_convert_order_address>
<vendor_account>
<to_quote_address>*</to_quote_address>
</vendor_account>
</sales_convert_order_address>
<sales_convert_quote_address>
<vendor_account>
<to_order_address>*</to_order_address>
<to_customer_address>*</to_customer_address>
</vendor_account>
<primary_business>
<to_order_address>*</to_order_address>
<to_customer_address>*</to_customer_address>
</primary_business>
</sales_convert_quote_address>
</fieldsets>
</global>
</config>
我正在在billing.phtml文件中的行下面編寫代碼,以在business.php
類方法getAlloptions();
調用getAlloptions();
<?php echo Mage::getModel('partsimple/customFields_model_primarybusiness_business')->getAllOptions();?>
我也嘗試過打印課
<?php echo "Class: ".get_class(Mage::getModel('partsimple/customfields_model_primarybusiness_business'));?>
但是我什么也沒得到。 請讓我知道我做錯了什么,我想在billing.phtml上調用此方法。
在config.xml文件中進行更正后,其工作正常。
要檢查
config.xml
錯誤,請在>任何編輯器中進行編輯后在瀏覽器中打開此文件,以便顯示錯誤。
現在,該屬性顯示結帳頁面和管理客戶頁面以及客戶我的帳戶部分,但在此部分中。 我無法更新。 customer_account標記中需要在config.xml中添加哪些字段。
我在config.xml中添加了這樣的內容
<customer_account>
<primary_business>
<create>1</create>
<update>1</update>
</primary_business>
</customer_account>
您是否將此文件添加到名為Partsimple_CustomFields.xml的app / etc / modules中:
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Partsimple_CustomFields>
<active>true</active>
<codePool>community</codePool>
</Partsimple_CustomFields>
</modules>
</config>
您已經說過magento,您的模型將在config.xml中使用“ Partsimple_CustomFields”進行調用,因此您應始終使用名稱“ Partsimple_CustomFields”來調用模型,如下所示:
<?php echo Mage::getModel('Partsimple_CustomFields/primarybusiness_business')->getAllOptions();?>
您需要查看您的<models>
節點。 您已將模型分組為Partsimple_CustomFields,但是您正在嘗試使用此Mage::getModel('partsimple/customFields_model_primarybusiness_business')
實例化您的類。 您需要更改模型節點中的第一個節點,如下所示
<models>
<partsimple>
<class>Partsimple_CustomFields_Model</class>
</partsimple>
</models>
或者您需要像這樣實例化模型:
Mage::getModel('Partsimple_CustomFields/customfields_model_primarybusiness_business')
<models>, <blocks>, and <helpers>
內的第一個節點是您的分組節點。 當Magento嘗試確定要實例化的Mage_Core_Model_Config::getGroupedClassName($groupType, $classId, $groupRootNode)
時,將調用Mage_Core_Model_Config::getGroupedClassName($groupType, $classId, $groupRootNode)
將Partsimple_CustomFields / customfields_model_primarybusiness_business轉換為實際的類名。 它檢查您的config.xml。
我還應該提到,通常的做法是在模型,塊和幫助程序節點中根本不使用任何大寫字母。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.