rwhite35 Posted July 21, 2015 Share Posted July 21, 2015 Work through the Skeleton Application::Module section for ZF2. Application is displaying the default ZF2 landing page (module/Application/view/application/index/index.phtml). And I've set up a test/ directory in my module then ran phpunit test. The test checks out and it returns OK (7 tests, 16 assertions). As far as I can tell, the application through Database and Modules is setup correctly. However when I go to load the module page, I get a blank page with one line of text: missing.html. Setup: Module Name: Guestbook App Path: octoberblue.net/guestbook Virtual Host: guestbook.octoberblue.net Directory(httpd-vhosts.conf): guestbook/public mod_rewrite enabled .htaccess configured Current file structure My module name is Guestbook and I'm porting the ZF1 guestbook Skeleton project to ZF2. Error_log when loading guestbook.october.net/guestbook (the suggested method) File does not exist: /opt/local/apache2/htdocs/octoberblue/guestbook/public/guestbook BTW, the framework is returning the error/text. If I try and load the module viewer (view/guestbook/guestbook/index.phtml) by entering the absolute real path in the browser address bar, I get a different error in the error_log, that error is: .htaccess: Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configuration Any thoughts appreciated. Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/297415-zf2-missinghtml-error-on-module-load/ Share on other sites More sharing options...
rwhite35 Posted July 22, 2015 Author Share Posted July 22, 2015 To help drill the problem down more. The ViewModel method renders the html. Here is the machinery involved. /view/guestbook/guestbook/index.phtml <?php $title = 'My Guestbook'; $this->headTitle($title); ?> <h1><?php echo $this->escapeHtml($title); ?></h1> <p> <a href="<?php echo $this->url('guestbook', array('action'=>'add'));?>">Add</a> </p> <table class="table"> <tr> <th>Title</th> <th>Artist</th> <th> </th> </tr> <?php //$guestbooks array defined in GuestbookController class foreach ($guestbooks as $guestbook) : ?> <tr> <td><?php echo $this->escapeHtml($guestbook->user);?></td> <td><?php echo $this->escapeHtml($guestbook->message);?></td> <td> <a href="<?php echo $this->url('guestbook', array('action'=>'edit', 'id' => $guestbook->id));?>">Edit</a> <a href="<?php echo $this->url('guestbook', array('action'=>'delete', 'id' => $guestbook->id));?>">Delete</a> </td> </tr> <?php endforeach; ?> </table> /src/Guestbook/Controller/GuestbookController.php namespace Guestbook\Controller; use Zend\Mvc\Controller\AbstractActionController; use Zend\View\Model\ViewModel; class GuestbookController extends AbstractActionController { protected $guestbookTable; public function indexAction() { return new ViewModel(array( 'guestbooks' => $this->getGuestbookTable()->fetchAll(), )); } //rest is omitted for brevity /src/Guestbook/Model/Guestbook.php namespace Guestbook\Model; class Guestbook { public $id; public $user; public $message; public function exchangeArray($data) { $this->id = (isset($data['id'])) ? $data['id'] : null; $this->user = (isset($data['user'])) ? $data['user'] : null; $this->message = (isset($data['message'])) ? $data['message'] : null; } } /config/module.config.php return array( 'controllers' => array( // list of all module controllers 'invokables' => array( // [controller_reference] = [controller_string] 'Guestbook\Controller\Guestbook' => 'Guestbook\Controller\GuestbookController', ), ), //map actions to URL patterns with router action->route->url 'router' => array( 'routes' => array( 'guestbook' => array( 'type' => 'segment', 'options' => array( 'route' => '/guestbook[/:action][/:id]', 'constraints' => array( 'action' => '[a-zA-Z][a-zA-Z0-9_-]*', 'id' => '[0-9]*', ), 'defaults' => array( 'controller' => 'Guestbook\Controller\Guestbook', 'action' => 'index', ), ), ), ), ), // defines location of module viewer scripts 'view_manager' => array( 'template_path_stack' => array( 'guestbook' => __DIR__ . '/../view', ), ), ); Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/297415-zf2-missinghtml-error-on-module-load/#findComment-1517042 Share on other sites More sharing options...
rwhite35 Posted July 22, 2015 Author Share Posted July 22, 2015 (edited) After a lot of reading and experimentation, its working. The problem seems to be in the modules router. Using the above router in Guestbook/config/module.config.php, the ServiceManager was registering everything, but wasn't finding the module resources. After reading through the ZF2.4 manual here I've changed the router to: 'router' => array( 'routes' => array( 'guestbook' => array( 'type' => 'Segment', 'options' => array( 'route' => '/[:controller[/:action]]', 'defaults' => array( '__NAMESPACE__' => 'Guestbook\Controller', 'controller' => 'Guestbook', 'action' => 'index', ), 'constraints' => [ 'controller' => '[a-zA-Z][a-zA-Z0-9_-]*', 'action' => '[a-zA-Z][a-zA-Z0-9_-]*', ] ), // options ) // guestbook ) // routes ), // router This router setup is serving the page as I would have expected. Edited July 23, 2015 by rwhite35 Quote Link to comment https://forums.phpfreaks.com/topic/297415-zf2-missinghtml-error-on-module-load/#findComment-1517129 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.