我是 Zend Framework 2 编码的新手,我的布局和控制器有问题:
当我浏览vhost/时,它会呈现我的布局和 index.phtml 视图;所以一切都好!
但是,当我浏览vhost/cv时,它只呈现 cv.phtml 而没有我的布局......
这是我的代码
模块.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',
),
),
);
家庭控制器.php
class HomeController extends AbstractActionController
{
public function indexAction()
{
return new ViewModel();
}
public function cvAction()
{
return new ViewModel();
}
}
我尝试使用 2 个控制器,使用子路由,但这些都不起作用......
有人可以告诉我我的代码有什么问题吗?
谢谢,麦克西姆
编辑 :
布局.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>
简历.phtml
<h1 class='heading-1 small-separator'>
// My heading
</h1>
<section>
// All my CV
</section>
索引.phtml
<!-- Presentation -->
<?php require('_presentation.php'); ?>
<!-- End Presentation -->
<!-- Prestations -->
<?php require('_prestations.php'); ?>
<!-- End Prestations -->
<!-- Contact -->
<?php require('_contact.php'); ?>
<!-- End Contact -->