💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
1.在view/frontend/layout/cms_cms_index.xml ~~~ <?xml version="1.0"?> <!-- /** * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ --> <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> <body> <referenceContainer name="content"> <block name="blockextend.front.front" class="Njzz\BlockExtend\Block\Cms\Index\Index" template="Njzz_BlockExtend::cms/index/index.phtml"/> </referenceContainer> </body> </page> template="Njzz_BlockExtend::cms/index/index.phtml":模板位置 class="Njzz\BlockExtend\Block\Cms\Index\Index" block的命名空间+类名 ~~~ 2.block block/Cms/Index/Index.php ~~~ <?php /** * Created by PhpStorm. * User: daimingkang * Date: 2016/3/12 * Time: 14:46 */ namespace Njzz\BlockExtend\Block\Cms\Index; class Index extends \Magento\Catalog\Block\Product\ListProduct{ public function index(){ echo '1111111111'; } } ~~~ 3.view/frontend/templates/cms/index/index.phtml ~~~ <?php /** * * @var $block \Njzz\BlockExtend\Block\Cms\Index\Index */ echo $block->index(); ?> ~~~ 页面输出1111111111