Zend Framework 2:布局仅在索引操作上呈现


Zend Framework 2 : Layout only rendering on index action

我是Zend Framework 2编码的新手,我的布局和控制器有问题:

当我浏览vhost/时,它会呈现我的布局和index.phtml视图;所以一切都很好!

但是,当我浏览 vhost/cv 时,它只渲染 cv.phtml 而没有我的布局......

这是我的代码

模块配置.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>

cv.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 -->

好的,我解决了我的问题,所以这真的是假的(是的,我是)错误:

我已经在cv.phtml上放了一个链接:

<a href='$this.basePath()'>my link</a>

所以每次我尝试渲染布局 + 视图时,视图脚本都会抛出异常:"$this.basePath() 是一个未知函数"

我昨天:"哇?!那为什么呢?我把它用在index.phtml中!

我今天:"真是一团糟!PHP 使用 -> 调用对象方法,而不是 '.'。

因此,视图脚本 cv.phtml 没有任何错误,它可以在我的布局中正常工作。

感谢

大家的回复,感谢Jurian Sluiman,他证实了我的cv.phtml可能有错误。