[英]magento module block not working and how to use observer
我是magento模塊開發的新手,目前正在開發模塊,但是我只能停留在一條線上,並且每次失敗時都想學習觀察者。當前,我想獲取所有產品列表,但沒有結果,也沒有錯誤。 有什么幫助嗎?
這是我的嘗試
在 :app / etc / modules / Abc_Mymodule.xml
<?xml version="1.0"?>
<config>
<modules>
<Abc_Mymodule>
<active>true</active>
<codePool>local</codePool>
</Abc_Mymodule>
</modules>
</config>
我在app / code / local / Abc / Mymodule / etc / config.xml中的配置文件
<?xml version="1.0"?>
<config>
<modules>
<Abc_Mymodule>
<version>0.4.0</version> <!-- Version number of your module -->
</Abc_Mymodule>
</modules>
<global>
<models>
<catalog>
<rewrite>
<product_type>Abc_Mymodule_Model_Product_Type</product_type>
</rewrite>
</catalog>
<Mymodule>
<class>Abc_Mymodule_Model</class>
<resourceModel>Mymodule_Mysql4</resourceModel>
</Mymodule>
</models>
<resources>
<Mymodule_setup>
<setup>
<module>Abc_Mymodule</module>
<class>Abc_Mymodule_Model_Resource_Setup</class>
</setup>
</Mymodule_setup>
</resources>
<blocks>
<Mymodule>
<class>Abc_Mymodule_Block</class>
</Mymodule>
</blocks>
</global>
<frontend>
<routers>
<mymodule>
<use>standard</use>
<args>
<module>Abc_Mymodule</module>
<frontName>Mymodule</frontName>
</args>
</mymodule>
</routers>
<layout>
<updates>
<Mymodule>
<file>Mymodule.xml</file>
</Mymodule>
</updates>
</layout>
</frontend>
</config>
我的控制器是app / code / local / Abc / Mymodule / controllers / PpController.php
<?php
class Abc_Mymodule_PpController extends Mage_Core_Controller_Front_Action
{
public function productlistAction(){
/*
$block = $this->getLayout()->createBlock('Mymodule/Productlist');
$cole1 = $block->getCollection();
print_r($cole1);
die;*/
$this->loadLayout();
$this->renderLayout();
}
public function postcategoryAction(){
$userid = Mage::getSingleton('customer/session')->getCustomer()->getId();
$parentId = '64';
$title = $this->getRequest()->getPost('category_name');
$url=$this->getRequest()->getPost('category_url');
try{
$category = Mage::getModel('catalog/category');
$category->setName($title);
$category->setUrlKey($url);
$category->setcuid($userid);
$category->setIsActive(0);
$category->setDisplayMode('PRODUCTS');
$category->setIsAnchor(0); //for active achor
$category->setStoreId(Mage::app()->getStore()->getId());
$parentCategory = Mage::getModel('catalog/category')->load($parentId);
$category->setPath($parentCategory->getPath());
$category->save();
} catch(Exception $e) {
var_dump($e);
}
Mage::getSingleton('core/session')->addSuccess('Category has been successfully added');
$this->_redirect('customer/account');
}
public function categorylistAction(){
$this->loadLayout();
$this->renderLayout();
}
?>
我的區塊是app / code / local / Abc / Mymodule / Block
<?php
class Abc_Mymodule_Block_Productlist extends Mage_Core_Block_Template
{
private $cuserid = null;
private $store_id = null;
protected function _construct()
{
// $cat33 = $this->getCurrentCategory();
$this->store_id = Mage::app()->getStore()->getId();
//parent::__construct();
$this->cuserid = Mage::getSingleton('customer/session')->getCustomer()->getId();
$collection = Mage::getModel('catalog/product')->getCollection();
/*$collection = Mage::getModel('catalog/product')
->getCollection()
->addAttributeToSelect('*')
->addAttributeToFilter('mmuserid', array('eq' => $this->cuserid))
->load();*/
$this->setCollection($collection);
}
?>
我想使用事件有關觀察者或事件的任何幫助嗎?
這是我的mymodul
<?xml version="1.0"?>
<layout version="0.1.0">
<mymodule_pp_product>
<reference name="root">
<action method="setTemplate"><template>page/2columns-left.phtml</template></action>
<action method="addBodyClass"><class>customer-account</class></action>
</reference>
<reference name="content" >
<block type="Mymodule/Productadd" name="productadd" template="mymodule/productadd.phtml" />
</reference>
<reference name="left">
<block type="customer/account_navigation" name="customer_account_navigation" before="-" template="customer/account/navigation.phtml">
<action method="addLink" translate="label" module="customer"><name>account</name><path>customer/account/</path><label>Account Dashboard</label></action>
<action method="addLink" translate="label" module="customer"><name>account_edit</name><path>customer/account/edit/</path><label>Account Information</label></action>
<action method="addLink" translate="label" module="customer"><name>address_book</name><path>customer/address/</path><label>Address Book</label></action>
</block>
</reference>
</mymodule_pp_product>
</layout>
好的,沒有答案。實際上,我指出了阻止不起作用的原因,這是一個小的拼寫錯誤,現在我已經編輯了問題,現在可以正確拼寫並為我工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.