这是我的控制器动作类
<?php
namespace Felix\HelloMod\Controller\Files;
use Magento\Framework\App\Action\Action;
use Magento\Framework\App\Action\Context;
use Magento\Framework\View\Result\PageFactory;
class ProductFiles extends Action
{
protected $_pagefactory;
public function _construct(Context $context, PageFactory $pageFactory){
$this->_pagefactory = $pageFactory;
return parent::_construct($context);
}
public function execute(){
return $this->_pagefactory->create();
}
}
我遇到以下错误:
致命错误:未被捕获的错误:在C:\ xampp \ htdocs \ Mage2 \ app \ code \ Felix \ HelloMod \ Controller \ Files \ ProductFiles.php:15中对null调用成员函数create():15堆栈跟踪:# 0 C:\ xampp \ htdocs \ Mage2 \ Generated \ code \ Felix \ HelloMod \ Controller \ Files \ ProductFiles \ Interceptor.php(37):Felix \ HelloMod \ Controller \ Files \ ProductFiles-> execute()#1 C:\ xampp \ htdocs \ Mage2 \ vendor \ magento \ framework \ App \ Action \ Action.php(107):Felix \ HelloMod \ Controller \ Files \ ProductFiles \ Interceptor-> execute()#2 C:\ xampp \ htdocs \ Mage2 \ vendor \ magento \ framework \ Interception \ Interceptor.php(58):Magento \ Framework \ App \ Action \ Action-> dispatch(Object(Magento \ Framework \ App \ Request \ Http))#3 C:\ xampp \ htdocs \ Mage2 \ vendor \ magento \ framework \ Interception \ Interceptor.php(138):Felix \ HelloMod \ Controller \ Files \ ProductFiles \ Interceptor-> ___ callParent('dispatch',Array)#4 C:\ xampp \ htdocs \ Mage2 \ vendor \ magento \ framework \ Interception \ Interceptor.php(153):Felix \ HelloMod \ Controller \ Files \ ProductFiles \ Interceptor-> Magento \ Framework \ Interce ption {closure}(对象(第15行的C:\ xampp \ htdocs \ Mage2 \ app \ code \ Felix \ HelloMod \ Controller \ Files \ ProductFiles.php中的Magento \ Framework
答案 0 :(得分:1)
我错过了构造函数方法的双下划线,并运行php bin / magento setup:di:compile并成功了。
<?php
namespace Felix\HelloMod\Controller\Files;
use Magento\Framework\App\Action\Action;
use Magento\Framework\App\Action\Context;
use Magento\Framework\View\Result\PageFactory;
class ProductFiles extends Action
{
protected $_pagefactory;
public function __construct(Context $context, PageFactory $pageFactory){
$this->_pagefactory = $pageFactory;
return parent::__construct($context);
}
public function execute(){
return $this->_pagefactory->create();
}
}