I'm new on Zend Framework 2 coding, and I've a problem with my layouts and controllers :
When I browse vhost/, it renders my layout and the index.phtml view; so everything is OK !
But, when I browse vhost/cv, it only renders the cv.phtml without my layout...
Here is my code
module.config.php
return array(
'controllers' => array(
'invokables' => array(
'Portfolio\Controller\Home' => 'Portfolio\Controller\HomeController',
),
),
'router' => array(
'routes' => array(
'home' => array(
'type' => 'Literal',
'options' => array(
'route' => '/',
'defaults' => array(
'controller' => 'Portfolio\Controller\Home',
'action' => 'index',
),
),
),
'cv' => array(
'type' => 'Literal',
'options' => array(
'route' => '/cv',
'defaults' => array(
'controller' => 'Portfolio\Controller\Home',
'action' => 'cv',
),
),
),
),
),
'view_manager' => array(
'display_not_found_reason' => true,
'display_exceptions' => true,
'doctype' => 'HTML5',
'not_found_template' => 'error/404',
'exception_template' => 'error/index',
'template_map' => array(
'layout/layout' => __DIR__ . '/../view/layout/layout.phtml',
'error/404' => __DIR__ . '/../view/error/404.phtml',
'error/index' => __DIR__ . '/../view/error/index.phtml',
),
'template_path_stack' => array(
__DIR__ . '/../view',
),
),
);
HomeController.php
class HomeController extends AbstractActionController
{
public function indexAction()
{
return new ViewModel();
}
public function cvAction()
{
return new ViewModel();
}
}
I tried using 2 controllers, using child routes, and none of these worked...
Can someone tell me what is wrong with my code ?
Thanks, McSIME
EDIT :
layout.phtml
<?php echo $this->doctype(); ?>
<html lang='fr'>
<head>
<meta charset='utf-8' />
<link rel='stylesheet' type='text/css' href='<?php echo $this->basePath() . '/css/bootstrap.min.css' ?>' />
<link rel='stylesheet/less' type='text/css' href='<?php echo $this->basePath() . '/css/base.less'; ?>' />
<link rel='shortcut icon' href='<?php echo $this->basePath() . '/img/favicon.ico'; ?>' />
<?php echo $this->headScript()
->prependFile($this->basePath() . '/js/ga.js')
->prependFile($this->basePath() . '/js/global.js')
->prependFile($this->basePath() . '/js/less-1.4.1.min.js')
->prependFile($this->basePath() . '/js/bootstrap.min.js')
->prependFile($this->basePath() . '/js/jquery-1.10.2.min.js')
; ?>
<title>Test</title>
</head>
<body data-spy='scroll' data-target='#header' data-offset='200'>
<?php require($this->basePath() . 'temp-old/views/shared/header.php') ?>
<div id='content'>
<?php echo $this->content; ?>
<?php require($this->basePath() . 'temp-old/views/shared/footer.php') ?>
</div>
</body>
</html>
cv.phtml
<h1 class='heading-1 small-separator'>
// My heading
</h1>
<section>
// All my CV
</section>
index.phtml
<!-- Presentation -->
<?php require('_presentation.php'); ?>
<!-- End Presentation -->
<!-- Prestations -->
<?php require('_prestations.php'); ?>
<!-- End Prestations -->
<!-- Contact -->
<?php require('_contact.php'); ?>
<!-- End Contact -->
cv.phtml
you have an error. – Jurian Sluiman