Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/297.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/magento/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Magento扩展:如何在CMS页面或块上输出字符串_Php_Magento - Fatal编程技术网

Php Magento扩展:如何在CMS页面或块上输出字符串

Php Magento扩展:如何在CMS页面或块上输出字符串,php,magento,Php,Magento,我正在尝试创建我的第一个Magento扩展,但我已经被困在了第一步 将{{block type=“rick_printer/print”text=“Hello world”}添加到CMS页面或块时,我希望显示“Hello world”。 不幸的是什么也没发生。这是我的密码: app\code\local\Rick\Printer\etc\config.xml <?xml version="1.0" encoding="UTF-8"?> <config> <

我正在尝试创建我的第一个Magento扩展,但我已经被困在了第一步

{{block type=“rick_printer/print”text=“Hello world”}
添加到CMS页面或块时,我希望显示“Hello world”。 不幸的是什么也没发生。这是我的密码:

app\code\local\Rick\Printer\etc\config.xml

<?xml version="1.0" encoding="UTF-8"?>
<config> 
    <modules>
        <Rick_Printer>
            <version>0.0.1</version>
        </Rick_Printer>
    </modules>
    <global>
        <blocks>
            <rick_printer>
                <class>Rick_Printer_Block_Print</class>
            </rick_printer>
        </blocks>
    </global>
</config>
<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <Rick_Printer>
            <active>true</active>
            <codePool>local</codePool>
        </Rick_Printer>
    </modules>
</config>
<?php
    $text = $this->spinIt();
    echo $text;
?>
app\design\frontend\default\default\template\rick\printer\print.phtml

<?xml version="1.0" encoding="UTF-8"?>
<config> 
    <modules>
        <Rick_Printer>
            <version>0.0.1</version>
        </Rick_Printer>
    </modules>
    <global>
        <blocks>
            <rick_printer>
                <class>Rick_Printer_Block_Print</class>
            </rick_printer>
        </blocks>
    </global>
</config>
<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <Rick_Printer>
            <active>true</active>
            <codePool>local</codePool>
        </Rick_Printer>
    </modules>
</config>
<?php
    $text = $this->spinIt();
    echo $text;
?>

首先,您的块类前缀是错误的。尽管节点名为
,但您实际指定的是类前缀
另一种方式是,该节点声明模块块所在的目录。
正确的方法是

<!-- language: xml -->
<global>
    <blocks>
        <rick_printer>
            <class>Rick_Printer_Block</class>
        </rick_printer>
    </blocks>
</global>

Rick_打印机_块
其次,在模板中调用
$this->spinIt()
而不是
$this->printIt()。
只是打字错误

否则代码看起来没问题

更新
错误消息表示文件系统路径与类名不匹配。检查外壳和印刷字体。

另外,由于您希望块渲染模板,因此希望从
Mage\u Core\u block\u template
扩展
Rick\u Printer\u block\u Print
,而不是
\u Abstract
块类。

谢谢。现在我得到了:
class Rick\u Printer\u Block\u Print扩展了Mage\u Core\u Block\u Abstract{protected function\u construct(){$this->setTemplate('Rick/Printer/view.phtml');parent::\u construct();}公共函数printIt(){$text=$this->getText();if(!$text){$msg=“请提供一个文本!”;echo$msg;return array();}return$text;}}致命错误:在第491行的/home/www/xyz/htdocs/app/code/core/Mage/core/Model/Layout.php中找不到类'Rick_Printer_Block_Print',请用其他信息更新您的原始帖子,然后在此处发布一条简短评论,提醒我这些更改。我不知道如何正确设置评论格式。更新了底部的原始帖子。谢谢错误消息表示文件系统路径与类名不匹配。检查打字错误和大小写。我也更新了我的答案。