我是magento的新手我想创建一个Hello World模块我遵循许多教程但我总是得到404错误
我的app / etc / module文件
<?xml version="1.0"?>
<config>
<modules>
<Quinchy_Demo>
<active>true</active>
<codePool>local</codePool>
</Quinchy_Demo>
</modules>
</config>
我的Php clas文件在app / local / Quinchy / Demo中
<?php
class Quinchy_Demo_Model_Hotel extends Mage_Core_Controller_Front_Action{
public function indexAction()
{
echo "Hello Quinchy";
}
}
?>
和配置文件是
<?xml version="1.0"?>
<config>
<modules>
<Quinchy_Demo>
<version>0.1.0</version>
</Quinchy_Demo>
</modules>
<frontend>
<routers>
<quinchy>
<use>standard</use>
<args>
<module>Quinchy_Demo</module>
<frontName>quinchy</frontName>
</args>
</quinchy>
</routers>
</frontend>
</config>
我使用此URL调用此模块
127.0.0.1/magento/index.php/quinchy,
127.0.0.1/magento/quinchy/
127.0.0.1/magento/quinchy/index
文件结构 enter image description here 请帮帮我
答案 0 :(得分:0)
您的“模型”实际上应该是一个控制器,它是为前端或adminhtml区域提供内容的类的类型。模型用于处理数据。
为您的控制器试试这个:
# File: app/code/local/Quinchy/Demo/controllers/HotelController.php
<?php
class Quinchy_Demo_HotelController extends Mage_Core_Controller_Front_Action
{
public function indexAction()
{
echo "Hello Quinchy";
exit;
}
}
顺便说一句,您可以通过/magento/quinchy/hotel/index
答案 1 :(得分:0)
您的控制器应位于“app / local / Quinchy / Demo / controllers / IndexController.php”文件中。类名应为'Quinchy_Demo_IndexController'(namespace traditional_poker
{
public class poker
{
public class hand // use PascalCaseNamingConvention
{
public String Name
{
get; set;
}
public String[] cards // use PascalCaseNamingConvention
{
get; set;
}
}
List<hand> players;
public void AddPlayer(String name)
{
hand newHand = new hand();
newHand.Name = name;
players.Add(newHand); //null reference exception here! you should initialize players
}
}
}
)。
您的扩展程序应如下所示:
class Quinchy_Demo_IndexController extends Mage_Core_Controller_Front_Action
:
app/etc/modules/Quinchy_Demo.xml
<?xml version="1.0"?>
<config>
<modules>
<Quinchy_Demo>
<active>true</active>
<codePool>local</codePool>
</Quinchy_Demo>
</modules>
</config>
:
app/code/local/Quinchy/Demo/etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<Quinchy_Demo>
<version>0.1.0</version>
</Quinchy_Demo>
</modules>
<frontend>
<routers>
<quinchy>
<use>standard</use>
<args>
<module>Quinchy_Demo</module>
<frontName>quinchy</frontName>
</args>
</quinchy>
</routers>
</frontend>
</config>
:
app/code/local/Quinchy/Demo/controllers/IndexController.php