我为什么会收到致命错误:require():无法使用zend打开所需的init_autoloader.php

时间:2016-10-19 06:11:31

标签: php zend-framework

我正在使用ubuntu 15.10并且我已经安装了 zend 3 我是zend框架的新手,所以我在从zend官方教程设置所有东西之后开始使用它的Skeleton Application教程我收到此错误: -

Warning: require(init_autoloader.php): failed to open stream: No such file or directory in /var/www/html/zendapp/public/index.php on line 25

Fatal error: require(): Failed opening required 'init_autoloader.php' (include_path='.:/usr/share/php') in /var/www/html/zendapp/public/index.php on line 25

我的index.php代码: -

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
 /**
  * Display all errors when APPLICATION_ENV is development.
  */
 if ($_SERVER['APPLICATION_ENV'] == 'development') {
     error_reporting(E_ALL);
     ini_set("display_errors", 1);
 }

 /**
  * This makes our life easier when dealing with paths. Everything is relative
  * to the application root now.
  */
 chdir(dirname(__DIR__));

 // Decline static file requests back to the PHP built-in webserver
 if (php_sapi_name() === 'cli-server' && is_file(__DIR__ . parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH))) {
     return false;
 }

 // Setup autoloading
 require 'init_autoloader.php';

 // Run the application!
 Zend\Mvc\Application::init(require 'config/application.config.php')->run();

请帮我解决这个问题,或者告诉我是否需要安装任何php模块谢谢。

更新: - 经过大量的研究后,我的添加,删除功能和查看文件都正常工作,但当我点击相册的编辑链接时,我收到一个错误: -

Zend\Stdlib\Exception\BadMethodCallException

File:

    /var/www/html/zendapp/vendor/zendframework/zendframework/library/Zend/Stdlib/Hydrator/ArraySerializable.php:29

Message:

    Zend\Stdlib\Hydrator\ArraySerializable::extract expects the provided object to implement getArrayCopy()

Stack trace:

    #0 /var/www/html/zendapp/vendor/zendframework/zendframework/library/Zend/Form/Fieldset.php(590): Zend\Stdlib\Hydrator\ArraySerializable->extract(Object(Album\Model\Album))
    #1 /var/www/html/zendapp/vendor/zendframework/zendframework/library/Zend/Form/Form.php(881): Zend\Form\Fieldset->extract()
    #2 /var/www/html/zendapp/vendor/zendframework/zendframework/library/Zend/Form/Form.php(303): Zend\Form\Form->extract()
    #3 /var/www/html/zendapp/module/Album/src/Album/Controller/AlbumController.php(75): Zend\Form\Form->bind(Object(Album\Model\Album))
    #4 /var/www/html/zendapp/vendor/zendframework/zendframework/library/Zend/Mvc/Controller/AbstractActionController.php(83): Album\Controller\AlbumController->editAction()
    #5 [internal function]: Zend\Mvc\Controller\AbstractActionController->onDispatch(Object(Zend\Mvc\MvcEvent))
    #6 /var/www/html/zendapp/vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php(468): call_user_func(Array, Object(Zend\Mvc\MvcEvent))
    #7 /var/www/html/zendapp/vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php(207): Zend\EventManager\EventManager->triggerListeners('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
    #8 /var/www/html/zendapp/vendor/zendframework/zendframework/library/Zend/Mvc/Controller/AbstractController.php(117): Zend\EventManager\EventManager->trigger('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
    #9 /var/www/html/zendapp/vendor/zendframework/zendframework/library/Zend/Mvc/DispatchListener.php(114): Zend\Mvc\Controller\AbstractController->dispatch(Object(Zend\Http\PhpEnvironment\Request), Object(Zend\Http\PhpEnvironment\Response))
    #10 [internal function]: Zend\Mvc\DispatchListener->onDispatch(Object(Zend\Mvc\MvcEvent))
    #11 /var/www/html/zendapp/vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php(468): call_user_func(Array, Object(Zend\Mvc\MvcEvent))
    #12 /var/www/html/zendapp/vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php(207): Zend\EventManager\EventManager->triggerListeners('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
    #13 /var/www/html/zendapp/vendor/zendframework/zendframework/library/Zend/Mvc/Application.php(309): Zend\EventManager\EventManager->trigger('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
    #14 /var/www/html/zendapp/public/index.php(26): Zend\Mvc\Application->run()
    #15 {main}

代码文件

  • 编辑操作: -

    public function editAction()
     {
         $id = (int) $this->params()->fromRoute('id', 0);
         if (!$id) {
             return $this->redirect()->toRoute('album', array(
                 'action' => 'add'
             ));
         }
    
         // Get the Album with the specified id.  An exception is thrown
         // if it cannot be found, in which case go to the index page.
         try {
             $album = $this->getAlbumTable()->getAlbum($id);
         }
         catch (\Exception $ex) {
             return $this->redirect()->toRoute('album', array(
                 'action' => 'index'
             ));
         }
    
         $form  = new AlbumForm();
         $form->bind($album);
         $form->get('submit')->setAttribute('value', 'Edit');
    
         $request = $this->getRequest();
         if ($request->isPost()) {
             $form->setInputFilter($album->getInputFilter());
             $form->setData($request->getPost());
    
             if ($form->isValid()) {
                 $this->getAlbumTable()->saveAlbum($album);
    
                 // Redirect to list of albums
                 return $this->redirect()->toRoute('album');
             }
         }
    
         return array(
             'id' => $id,
             'form' => $form,
         );
     }
    

2)。 edit.phtml

<?php
 // module/Album/view/album/album/edit.phtml:

 $title = 'Edit album';
 $this->headTitle($title);
 ?>
 <h1><?php echo $this->escapeHtml($title); ?></h1>

 <?php
 $form = $this->form;
 $form->setAttribute('action', $this->url(
     'album',
     array(
         'action' => 'edit',
         'id'     => $this->id,
     )
 ));
 $form->prepare();

 echo $this->form()->openTag($form);
 echo $this->formHidden($form->get('id'));
 echo $this->formRow($form->get('title'));
 echo $this->formRow($form->get('artist'));
 echo $this->formSubmit($form->get('submit'));
 echo $this->form()->closeTag();

0 个答案:

没有答案