Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/253.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
Zendframework 3教程PHP致命错误:允许的内存大小XXXXXX字节已用尽_Php_Fatal Error_Zend Db_Zend Framework3 - Fatal编程技术网

Zendframework 3教程PHP致命错误:允许的内存大小XXXXXX字节已用尽

Zendframework 3教程PHP致命错误:允许的内存大小XXXXXX字节已用尽,php,fatal-error,zend-db,zend-framework3,Php,Fatal Error,Zend Db,Zend Framework3,我们尝试实施zf3教程: 在我们尝试将一个新的indexAction()放入RequestTable之前,这一切都很顺利: return new ViewModel([ 'albums' => $this->table->fetchAll(), ]);` fetchAll()具有以下定义: public function fetchAll() { return $this->tableGateway->select(); } 这样,网站就会变白,

我们尝试实施zf3教程:

在我们尝试将一个新的indexAction()放入RequestTable之前,这一切都很顺利:

return new ViewModel([
    'albums' => $this->table->fetchAll(),
]);`
fetchAll()具有以下定义:

public function fetchAll()
{
   return $this->tableGateway->select();
}
这样,网站就会变白,不会抛出任何与zendframework相关的错误。只有apache服务器显示:

PHP Fatal error:  Allowed memory size of 134217728 bytes exhausted (tried to allocate 66719744 bytes) in Unknown on line 0
我们的module.config.php的结构如下:

namespace Request;


use Request\Controller\RequestController;
use Zend\Db\Adapter\AdapterServiceFactory;
use Zend\Router\Http\Segment;
use Zend\Db\Adapter\AdapterInterface;

return [
    'dependencies' => [
        'factories' => [
            AdapterInterface::class => AdapterServiceFactory::class,
            ],
        ],

    'router' => [
        'routes' => [
            'request' => [
                'type'    => Segment::class,
                'options' => [
                    'route' => '/request[/:action[/:id]]',
                    'constraints' => [
                        'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
                        'id'     => '[0-9]+',
                    ],
                    'defaults' => [
                        'controller' => RequestController::class,
                        'action'     => 'index',
                    ],
                ],
            ],
        ],
    ],

    'view_manager' => [
        'template_path_stack' => [
            'album' => __DIR__ . '/../view',
        ],
    ],
];
return [
    'db' => [
        'driver' => 'pdo_mysql',
        'database'    => 'test_db',
        'username'  => 'db_tester',
        'password' => 'XXXXXX',
    ],
];
namespace Request;

use Zend\Db\Adapter\AdapterInterface;
use Zend\Db\ResultSet\ResultSet;
use Zend\Db\TableGateway\TableGateway;
use Zend\ModuleManager\Feature\ConfigProviderInterface;

class Module implements ConfigProviderInterface
{
    public function getConfig()
    {
        return include __DIR__ . '/../config/module.config.php';
    }


    public function getServiceConfig()
    {
        return [
            'factories' => [
                Model\RequestTable::class => function($container) {
                    $tableGateway = $container->get(Model\RequestTableGateway::class);
                    return new Model\RequestTable($tableGateway);
                },
                Model\RequestTableGateway::class => function ($container) {
                    $dbAdapter = $container->get(AdapterInterface::class);
                    $resultSetPrototype = new ResultSet();
                    $resultSetPrototype->setArrayObjectPrototype(new Model\Request());
                    return new TableGateway('request', $dbAdapter, null, $resultSetPrototype);
                },
            ],
        ];
    }

    public function getControllerConfig()
    {
        return [
            'factories' => [
                Controller\RequestController::class => function($container) {
                    return new Controller\RequestController(
                        $container->get(Model\RequestTable::class)
                    );
                },
            ],
        ];
    }
}
如果我们打电话

 public function fetchAll()
 {
     return $this->tableGateway->getTable();
 }
相反,网站不会变白,apache中不会记录错误。只是什么都没发生

我们的global.php应该包含与数据库相关的信息,如下所示:

namespace Request;


use Request\Controller\RequestController;
use Zend\Db\Adapter\AdapterServiceFactory;
use Zend\Router\Http\Segment;
use Zend\Db\Adapter\AdapterInterface;

return [
    'dependencies' => [
        'factories' => [
            AdapterInterface::class => AdapterServiceFactory::class,
            ],
        ],

    'router' => [
        'routes' => [
            'request' => [
                'type'    => Segment::class,
                'options' => [
                    'route' => '/request[/:action[/:id]]',
                    'constraints' => [
                        'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
                        'id'     => '[0-9]+',
                    ],
                    'defaults' => [
                        'controller' => RequestController::class,
                        'action'     => 'index',
                    ],
                ],
            ],
        ],
    ],

    'view_manager' => [
        'template_path_stack' => [
            'album' => __DIR__ . '/../view',
        ],
    ],
];
return [
    'db' => [
        'driver' => 'pdo_mysql',
        'database'    => 'test_db',
        'username'  => 'db_tester',
        'password' => 'XXXXXX',
    ],
];
namespace Request;

use Zend\Db\Adapter\AdapterInterface;
use Zend\Db\ResultSet\ResultSet;
use Zend\Db\TableGateway\TableGateway;
use Zend\ModuleManager\Feature\ConfigProviderInterface;

class Module implements ConfigProviderInterface
{
    public function getConfig()
    {
        return include __DIR__ . '/../config/module.config.php';
    }


    public function getServiceConfig()
    {
        return [
            'factories' => [
                Model\RequestTable::class => function($container) {
                    $tableGateway = $container->get(Model\RequestTableGateway::class);
                    return new Model\RequestTable($tableGateway);
                },
                Model\RequestTableGateway::class => function ($container) {
                    $dbAdapter = $container->get(AdapterInterface::class);
                    $resultSetPrototype = new ResultSet();
                    $resultSetPrototype->setArrayObjectPrototype(new Model\Request());
                    return new TableGateway('request', $dbAdapter, null, $resultSetPrototype);
                },
            ],
        ];
    }

    public function getControllerConfig()
    {
        return [
            'factories' => [
                Controller\RequestController::class => function($container) {
                    return new Controller\RequestController(
                        $container->get(Model\RequestTable::class)
                    );
                },
            ],
        ];
    }
}
这是我们的RequestTable.php:

namespace Request\Model;

use RuntimeException;
use Zend\Db\TableGateway\TableGatewayInterface;

class RequestTable
{
    private $tableGateway;

    /**
     * RequestTable constructor.
     * @param TableGatewayInterface $tableGateway
     */
    public function __construct(TableGatewayInterface $tableGateway)
    {
       $this->tableGateway = $tableGateway;
    }

    public function fetchAll()
    {
        return $this->tableGateway->select();
    }
这是request.php:

namespace Request\Model;

class Request{

    public $request_id;
    public $email;
    public $type;

    public function exchangeArray(array $data)
    {
        $this->request_id     = !empty($data['request_id']) ? $data['request_id'] : null;
        $this->email          = !empty($data['email']) ? $data['email'] : null;
        $this->type           = !empty($data['type']) ? $data['type'] : null;
    }


}
我们的Module.php如下所示:

namespace Request;


use Request\Controller\RequestController;
use Zend\Db\Adapter\AdapterServiceFactory;
use Zend\Router\Http\Segment;
use Zend\Db\Adapter\AdapterInterface;

return [
    'dependencies' => [
        'factories' => [
            AdapterInterface::class => AdapterServiceFactory::class,
            ],
        ],

    'router' => [
        'routes' => [
            'request' => [
                'type'    => Segment::class,
                'options' => [
                    'route' => '/request[/:action[/:id]]',
                    'constraints' => [
                        'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
                        'id'     => '[0-9]+',
                    ],
                    'defaults' => [
                        'controller' => RequestController::class,
                        'action'     => 'index',
                    ],
                ],
            ],
        ],
    ],

    'view_manager' => [
        'template_path_stack' => [
            'album' => __DIR__ . '/../view',
        ],
    ],
];
return [
    'db' => [
        'driver' => 'pdo_mysql',
        'database'    => 'test_db',
        'username'  => 'db_tester',
        'password' => 'XXXXXX',
    ],
];
namespace Request;

use Zend\Db\Adapter\AdapterInterface;
use Zend\Db\ResultSet\ResultSet;
use Zend\Db\TableGateway\TableGateway;
use Zend\ModuleManager\Feature\ConfigProviderInterface;

class Module implements ConfigProviderInterface
{
    public function getConfig()
    {
        return include __DIR__ . '/../config/module.config.php';
    }


    public function getServiceConfig()
    {
        return [
            'factories' => [
                Model\RequestTable::class => function($container) {
                    $tableGateway = $container->get(Model\RequestTableGateway::class);
                    return new Model\RequestTable($tableGateway);
                },
                Model\RequestTableGateway::class => function ($container) {
                    $dbAdapter = $container->get(AdapterInterface::class);
                    $resultSetPrototype = new ResultSet();
                    $resultSetPrototype->setArrayObjectPrototype(new Model\Request());
                    return new TableGateway('request', $dbAdapter, null, $resultSetPrototype);
                },
            ],
        ];
    }

    public function getControllerConfig()
    {
        return [
            'factories' => [
                Controller\RequestController::class => function($container) {
                    return new Controller\RequestController(
                        $container->get(Model\RequestTable::class)
                    );
                },
            ],
        ];
    }
}
添加后,现在我们得到以下失败消息:

var_dump(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS))
错误消息:

array(10) { [0]=> array(3) { ["file"]=> string(90) "/var/www/heinrich.jens.vawi.de/vendor/zendframework/zend-view/src/Renderer/PhpRenderer.php" ["line"]=> int(505) ["function"]=> string(7) "include" } [1]=> array(5) { ["file"]=> string(74) "/var/www/heinrich.jens.vawi.de/vendor/zendframework/zend-view/src/View.php" ["line"]=> int(207) ["function"]=> string(6) "render" ["class"]=> string(30) "Zend\View\Renderer\PhpRenderer" ["type"]=> string(2) "->" } [2]=> array(5) { ["file"]=> string(74) "/var/www/heinrich.jens.vawi.de/vendor/zendframework/zend-view/src/View.php" ["line"]=> int(236) ["function"]=> string(6) "render" ["class"]=> string(14) "Zend\View\View" ["type"]=> string(2) "->" } [3]=> array(5) { ["file"]=> string(74) "/var/www/heinrich.jens.vawi.de/vendor/zendframework/zend-view/src/View.php" ["line"]=> int(200) ["function"]=> string(14) "renderChildren" ["class"]=> string(14) "Zend\View\View" ["type"]=> string(2) "->" } [4]=> array(5) { ["file"]=> string(103) "/var/www/heinrich.jens.vawi.de/vendor/zendframework/zend-mvc/src/View/Http/DefaultRenderingStrategy.php" ["line"]=> int(105) ["function"]=> string(6) "render" ["class"]=> string(14) "Zend\View\View" ["type"]=> string(2) "->" } [5]=> array(5) { ["file"]=> string(90) "/var/www/heinrich.jens.vawi.de/vendor/zendframework/zend-eventmanager/src/EventManager.php" ["line"]=> int(322) ["function"]=> string(6) "render" ["class"]=> string(43) "Zend\Mvc\View\Http\DefaultRenderingStrategy" ["type"]=> string(2) "->" } [6]=> array(5) { ["file"]=> string(90) "/var/www/heinrich.jens.vawi.de/vendor/zendframework/zend-eventmanager/src/EventManager.php" ["line"]=> int(171) ["function"]=> string(16) "triggerListeners" ["class"]=> string(30) "Zend\EventManager\EventManager" ["type"]=> string(2) "->" } [7]=> array(5) { ["file"]=> string(80) "/var/www/heinrich.jens.vawi.de/vendor/zendframework/zend-mvc/src/Application.php" ["line"]=> int(367) ["function"]=> string(12) "triggerEvent" ["class"]=> string(30) "Zend\EventManager\EventManager" ["type"]=> string(2) "->" } [8]=> array(5) { ["file"]=> string(80) "/var/www/heinrich.jens.vawi.de/vendor/zendframework/zend-mvc/src/Application.php" ["line"]=> int(348) ["function"]=> string(15) "completeRequest" ["class"]=> string(20) "Zend\Mvc\Application" ["type"]=> string(2) "->" } [9]=> array(5) { ["file"]=> string(47) "/var/www/heinrich.jens.vawi.de/public/index.php" ["line"]=> int(62) ["function"]=> string(3) "run" ["class"]=> string(20) "Zend\Mvc\Application" ["type"]=> string(2) "->" } }
我们所做的一切都是按照上面发布的教程进行的。。。
不知道此错误消息的含义,您是否尝试返回
returnnewviewmodel(['text'=>'helloworld'])看看它是否像那样工作?是的,工作很好!现在我想知道你的控制器工厂在哪里,你在哪里注入你的表。你们的桌子工厂在哪里?也许这里有问题。否则,请尝试在fetchAll()方法中返回文本发布文本无效。已更新问题…是否尝试返回
return new ViewModel(['text'=>'hello world')看看它是否像那样工作?是的,工作很好!现在我想知道你的控制器工厂在哪里,你在哪里注入你的表。你们的桌子工厂在哪里?也许这里有问题。否则,请尝试在fetchAll()方法中返回文本发布文本无效。已更新问题。。。