我是 Magento 的新手。我正在尝试为 Magento 管理面板开发一个自定义模块。我的代码如下
位置:app/etc/modules
Digitab_Brandlogo.xml
<?xml version="1.0" encoding="utf-8"?>
<config>
<modules>
<Digitab_Brandlogo>
<active>true</active>
<codePool>local</codePool>
</Digitab_Brandlogo>
</modules>
</config>
位置:app/code/local/Digitab/Brandlogo/Block/Adminhtml
logo.php
<?php
class Digitab_Brandlogo_Block_Adminhtml_slider extends Mage_Adminhtml_Block_Widget_Grid_Container
{
public function __construct()
{
$this->_controller = 'adminhtml_brandlogo';
$this->_blockGroup = 'brandlogo';
$this->_headerText = Mage::helper('brandlogo')->__('Brand Logo Manager');
$this->_addButtonLabel = Mage::helper('brandlogo')->__('Add Brand');
parent::__construct();
}
}
位置:app/code/local/Digitab/Brandlogo/controllers/Adminhtml
IndexController.php
<?php
class Digitab_Brandlogo_Adminhtml_BrandlogoController extends Mage_Adminhtml_Controller_Action
{
public function indexAction()
{
$this->loadLayout();
$this->renderLayout();
}
}
位置:app/code/local/Digitab/Brandlogo/etc
config.xml
<?xml version="1.0"?>
<config>
<modules>
<digitab_brandlogo>
<version>1.0.0</version>
</digitab_brandlogo>
</modules>
<global>
<models />
<blocks />
<resources />
<extraconfig />
<helpers>
<digitab_brandlogo>
<class>Digitab_Brandlogo_Helper</class>
</digitab_brandlogo>
</helpers>
</global>
<admin>
<routers>
<digitab_brandlogo>
<use>admin</use>
<args>
<module>Digitab_brandlogo</module>
<frontName>brandlogo</frontName>
</args>
</digitab_brandlogo>
</routers>
</admin>
<adminhtml>
<layout>
<updates>
<brandlogo>
<file>brandlogo.xml</file>
</brandlogo>
</updates>
</layout>
</adminhtml>
</config>
位置:app/code/local/Digitab/Brandlogo/etc
adminhtml.xml
<?xml version="1.0"?>
<config>
<menu>
<digitab translate="title" module="digitab_brandlogo">
<title>Digitab</title>
<sort_order>110</sort_order>
<children>
<brandlogo>
<title>Brand Logo</title>
<sort_order>1</sort_order>
<action>brandlogo/adminhtml_brandlogo</action>
</brandlogo>
</children>
</digitab>
</menu>
</config>
位置:app/code/local/Digitab/Brandlogo/Helper
Data.php
<?php
class Digitab_Brandlogo_Helper_Data extends Mage_Core_Helper_Abstract
{
}
位置:app/design/adminhtml/default/default/layout
品牌标识.xml
<?xml version="1.0"?>
<layout version="0.1.0">
<brandlogo_adminhtml_brandlogo_index>
<reference name="content">
<block type="brandlogo/adminhtml_brandlogo" name="brandlogo" template="test.phtml"/>
</reference>
</brandlogo_adminhtml_brandlogo_index>
</layout>
位置:app/design/adminhtml/default/default/template
test.phtml
ABCD
我得到如下输出
如何显示模板??任何人都可以在这方面帮助我吗?谢谢
更新
我修改了我的文件如下,但它不工作。
位置:app/etc/modules
Digitab_Brandlogo.xml
<?xml version="1.0" encoding="utf-8"?>
<config>
<modules>
<Digitab_Brandlogo>
<active>true</active>
<codePool>local</codePool>
</Digitab_Brandlogo>
</modules>
</config>
位置:app/code/local/Digitab/Brandlogo/Block/Adminhtml
Brandlogo.php
<?php
class Digitab_Brandlogo_Block_Adminhtml_Brandlogo extends Mage_Adminhtml_Block_Widget_Grid_Container
{
public function __construct()
{
$this->_controller = 'adminhtml_brandlogo';
$this->_blockGroup = 'brandlogo';
$this->_headerText = Mage::helper('brandlogo')->__('Brand Logo Manager');
$this->_addButtonLabel = Mage::helper('brandlogo')->__('Add Brand');
parent::__construct();
}
}
位置:app/code/local/Digitab/Brandlogo/controllers/Adminhtml
品牌标识 Controller
<?php
class Digitab_Brandlogo_Adminhtml_BrandlogoController extends Mage_Adminhtml_Controller_Action
{
public function indexAction()
{
$this->loadLayout();
$this->renderLayout();
}
}
位置:app/code/local/Digitab/Brandlogo/etc
config.xml
<?xml version="1.0"?>
<config>
<modules>
<digitab_brandlogo>
<version>1.0.0</version>
</digitab_brandlogo>
</modules>
<global>
<models />
<blocks>
<brandlogo>
<class>Digitab_Brandlogo_Block</class>
</brandlogo>
</blocks>
<resources />
<extraconfig />
<helpers>
<digitab_brandlogo>
<class>Digitab_Brandlogo_Helper</class>
</digitab_brandlogo>
</helpers>
</global>
<admin>
<routers>
<digitab_brandlogo>
<use>admin</use>
<args>
<module>Digitab_brandlogo</module>
<frontName>brandlogo</frontName>
</args>
</digitab_brandlogo>
</routers>
</admin>
<adminhtml>
<layout>
<updates>
<brandlogo>
<file>brandlogo.xml</file>
</brandlogo>
</updates>
</layout>
</adminhtml>
</config>
位置:app/code/local/Digitab/Brandlogo/etc
adminhtml.xml
<?xml version="1.0"?>
<config>
<menu>
<digitab translate="title" module="digitab_brandlogo">
<title>Digitab</title>
<sort_order>110</sort_order>
<children>
<brandlogo>
<title>Brand Logo</title>
<sort_order>1</sort_order>
<action>brandlogo/adminhtml_brandlogo</action>
</brandlogo>
</children>
</digitab>
</menu>
</config>
位置:app/code/local/Digitab/Brandlogo/Helper
Data.php
<?php
class Digitab_Brandlogo_Helper_Data extends Mage_Core_Helper_Abstract
{
}
位置:app/design/adminhtml/default/default/layout
品牌标识.xml
<?xml version="1.0"?>
<layout version="0.1.0">
<brandlogo_adminhtml_brandlogo_index>
<reference name="content">
<block type="brandlogo/adminhtml_brandlogo" name="brandlogo" template="test.phtml"/>
</reference>
</brandlogo_adminhtml_brandlogo_index>
</layout>
位置:app/design/adminhtml/default/default/template
test.phtml
ABCD
但它不起作用。现在我可以在管理面板中看到一个空白的白页。谢谢
最佳答案
这是一个完整的答案:
位置:app/etc/modules
Digitab_Brandlogo.xml
看起来不错。
位置:app/code/local/Digitab/Brandlogo/Block/Adminhtml
此文件夹需要包含以下文件和文件夹:
app/code/local/Digitab/Brandlogo/Block/Adminhtml/Brandlogo/Grid.php
<?php
class Digitab_Brandlogo_Block_Adminhtml_Brandlogo_Grid extends Mage_Adminhtml_Block_Widget_Grid
{
public function __construct()
{
parent::__construct();
$this->setId('digitab_brandlogo_grid');
$this->setDefaultSort('increment_id');
$this->setDefaultDir('DESC');
$this->setSaveParametersInSession(true);
$this->setUseAjax(true);
}
public function getGridUrl()
{
return $this->getUrl('*/*/grid', array('_current'=>true));
}
}
app/code/local/Digitab/Brandlogo/Block/Adminhtml/Brandlogo.php
<?php
class Digitab_Brandlogo_Block_Adminhtml_Brandlogo extends Mage_Adminhtml_Block_Widget_Grid_Container
{
public function __construct()
{
$this->_blockGroup = 'digitab_brandlogo';
$this->_controller = 'adminhtml_brandlogo';
$this->_headerText = Mage::helper('digitab_brandlogo')->__('Brand Logo Manager');
parent::__construct();
$this->_addButtonLabel = Mage::helper('digitab_brandlogo')->__('Add Brand');
}
}
位置:app/code/local/Digitab/Brandlogo/Helper/Data.php
<?php
class Digitab_Brandlogo_Helper_Data extends Mage_Core_Helper_Abstract {}
位置:app/code/local/Digitab/Brandlogo/controllers/Adminhtml/BrandlogoController.php
<?php
class Digitab_Brandlogo_Adminhtml_BrandlogoController extends Mage_Adminhtml_Controller_Action
{
public function indexAction()
{
$this->loadLayout();
$this->renderLayout();
}
}
The main problem is with the way you have written the XML files.
位置:app/code/local/Digitab/Brandlogo/etc
1。 app/code/local/Digitab/Brandlogo/etc/config.xml 下面是 config.xml 的代码。
<?xml version="1.0"?>
<config>
<modules>
<Digitab_Brandlogo>
<version>1.0.0</version>
</Digitab_Brandlogo>
</modules>
<global>
<models />
<blocks>
<digitab_brandlogo>
<class>Digitab_Brandlogo_Block</class>
</digitab_brandlogo>
</blocks>
<resources />
<extraconfig />
<helpers>
<digitab_brandlogo>
<class>Digitab_Brandlogo_Helper</class>
</digitab_brandlogo>
</helpers>
</global>
<admin>
<routers>
<adminhtml>
<args>
<modules>
<digitab_brandlogo before="Mage_Adminhtml">Digitab_Brandlogo_Adminhtml</digitab_brandlogo>
</modules>
</args>
</adminhtml>
</routers>
</admin>
<adminhtml>
<layout>
<updates>
<brandlogo>
<file>brandlogo.xml</file>
</brandlogo>
</updates>
</layout>
</adminhtml>
</config>
2。 app/code/local/Digitab/Brandlogo/etc/adminhtml.xml 下面是 config.xml 的代码。
<?xml version="1.0"?>
<config>
<menu>
<digitab translate="title" module="digitab_brandlogo">
<title>Digitab</title>
<sort_order>110</sort_order>
<children>
<brandlogo>
<title>Brand Logo</title>
<sort_order>1</sort_order>
<action>adminhtml/brandlogo/index</action>
</brandlogo>
</children>
</digitab>
</menu>
</config>
位置:app/design/frontend/adminhtml/default/default/layout/brandlogo.xml
<?xml version="1.0"?>
<layout version="0.1.0">
<adminhtml_brandlogo_index>
<reference name="content">
<block type="digitab_brandlogo/adminhtml_brandlogo" name="brandlogo" template="test.phtml"/>
</reference>
</adminhtml_brandlogo_index>
</layout>
位置:app/design/frontend/adminhtml/default/default/template/test.phtml
看起来不错。
我已经在我的本地机器上检查了这段代码。在此处找到屏幕截图:
让我知道这是否适合您。
注意::遵循我的回答中提到的确切命名约定和文件夹名称以及代码
快乐编码...
关于php - 在 Magento 的管理模块中显示模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35110613/
假设我做了一个模块如下:m=Module.newdoclassCendend三个问题:除了对m的引用之外,还有什么方法可以访问C和m中的其他内容?我可以在创建匿名模块后为其命名吗(就像我输入“module...”一样)?如何在使用完匿名模块后将其删除,使其定义的常量不再存在? 最佳答案 三个答案:是的,使用ObjectSpace.此代码使c引用你的类(class)C不引用m:c=nilObjectSpace.each_object{|obj|c=objif(Class===objandobj.name=~/::C$/)}当然这取决于
作为我的Rails应用程序的一部分,我编写了一个小导入程序,它从我们的LDAP系统中吸取数据并将其塞入一个用户表中。不幸的是,与LDAP相关的代码在遍历我们的32K用户时泄漏了大量内存,我一直无法弄清楚如何解决这个问题。这个问题似乎在某种程度上与LDAP库有关,因为当我删除对LDAP内容的调用时,内存使用情况会很好地稳定下来。此外,不断增加的对象是Net::BER::BerIdentifiedString和Net::BER::BerIdentifiedArray,它们都是LDAP库的一部分。当我运行导入时,内存使用量最终达到超过1GB的峰值。如果问题存在,我需要找到一些方法来更正我的代
我正在使用i18n从头开始构建一个多语言网络应用程序,虽然我自己可以处理一大堆yml文件,但我说的语言(非常)有限,最终我想寻求外部帮助帮助。我想知道这里是否有人在使用UI插件/gem(与django上的django-rosetta不同)来处理多个翻译器,其中一些翻译器不愿意或无法处理存储库中的100多个文件,处理语言数据。谢谢&问候,安德拉斯(如果您已经在rubyonrails-talk上遇到了这个问题,我们深表歉意) 最佳答案 有一个rails3branchofthetolkgem在github上。您可以通过在Gemfi
我得到了一个包含嵌套链接的表单。编辑时链接字段为空的问题。这是我的表格:Editingkategori{:action=>'update',:id=>@konkurrancer.id})do|f|%>'Trackingurl',:style=>'width:500;'%>'Editkonkurrence'%>|我的konkurrencer模型:has_one:link我的链接模型:classLink我的konkurrancer编辑操作:defedit@konkurrancer=Konkurrancer.find(params[:id])@konkurrancer.link_attrib
我主要使用Ruby来执行此操作,但到目前为止我的攻击计划如下:使用gemsrdf、rdf-rdfa和rdf-microdata或mida来解析给定任何URI的数据。我认为最好映射到像schema.org这样的统一模式,例如使用这个yaml文件,它试图描述数据词汇表和opengraph到schema.org之间的转换:#SchemaXtoschema.orgconversion#data-vocabularyDV:name:namestreet-address:streetAddressregion:addressRegionlocality:addressLocalityphoto:i
我有一个包含模块的模型。我想在模块中覆盖模型的访问器方法。例如:classBlah这显然行不通。有什么想法可以实现吗? 最佳答案 您的代码看起来是正确的。我们正在毫无困难地使用这个确切的模式。如果我没记错的话,Rails使用#method_missing作为属性setter,因此您的模块将优先,阻止ActiveRecord的setter。如果您正在使用ActiveSupport::Concern(参见thisblogpost),那么您的实例方法需要进入一个特殊的模块:classBlah
我正在使用puppet为ruby程序提供一组常量。我需要提供一组主机名,我的程序将对其进行迭代。在我之前使用的bash脚本中,我只是将它作为一个puppet变量hosts=>"host1,host2"我将其提供给bash脚本作为HOSTS=显然这对ruby不太适用——我需要它的格式hosts=["host1","host2"]自从phosts和putsmy_array.inspect提供输出["host1","host2"]我希望使用其中之一。不幸的是,我终其一生都无法弄清楚如何让它发挥作用。我尝试了以下各项:我发现某处他们指出我需要在函数调用前放置“function_”……这
所以我在关注Railscast,我注意到在html.erb文件中,ruby代码有一个微弱的背景高亮效果,以区别于其他代码HTML文档。我知道Ryan使用TextMate。我正在使用SublimeText3。我怎样才能达到同样的效果?谢谢! 最佳答案 为SublimeText安装ERB包。假设您安装了SublimeText包管理器*,只需点击cmd+shift+P即可获得命令菜单,然后键入installpackage并选择PackageControl:InstallPackage获取包管理器菜单。在该菜单中,键入ERB并在看到包时选择
我试图在索引页中创建一个超链接,但它没有显示,也没有给出任何错误。这是我的index.html.erb代码。ListingarticlesTitleTextssss我检查了我的路线,我认为它们也没有问题。PrefixVerbURIPatternController#Actionwelcome_indexGET/welcome/index(.:format)welcome#indexarticlesGET/articles(.:format)articles#indexPOST/articles(.:format)articles#createnew_articleGET/article
我是rails的新手,想在form字段上应用验证。myviewsnew.html.erb.....模拟.rbclassSimulation{:in=>1..25,:message=>'Therowmustbebetween1and25'}end模拟Controller.rbclassSimulationsController我想检查模型类中row字段的整数范围,如果不在范围内则返回错误信息。我可以检查上面代码的范围,但无法返回错误消息提前致谢 最佳答案 关键是您使用的是模型表单,一种显示ActiveRecord模型实例属性的表单。c