Jump to content

Recommended Posts

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

gb2_moduleTree.jpg

 

 

 

 

 

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.

Link to comment
https://forums.phpfreaks.com/topic/297415-zf2-missinghtml-error-on-module-load/
Share on other sites

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.

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 by rwhite35
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.