在zend 2中从url中删除public

时间:2015-05-29 12:42:03

标签: zend-framework zend-framework2

我按照this链接对文件进行了更改。

它正常工作,但$this->basePath()无效 layout.phtml ,因为css和js没有加载

->prependStylesheet($this->basePath('public/css/bootstrap.min.css'))
->prependFile($this->basePath('public/js/html5shiv.js'),   'text/javascript', array('conditional' => 'lt IE 9',))

zendtest / htaccess的

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /zendtest/
RewriteCond %{REQUEST_URI} !/public [NC]
RewriteRule ^(.*)$ public/$1 [L]

zendtest \模块\应用程序\配置\ module.config.php

return array(
    'router' => array(
        'routes' => array(
            'home' => array(
                'type' => 'Zend\Mvc\Router\Http\Literal',
                'options' => array(
                    'route'    => '/zendtest/',
                    'defaults' => array(
                        'controller' => 'Application\Controller\Index',
                        'action'     => 'index',
                    ),
                ),
            ),

            'application' => array(
                'type'    => 'Literal',
                'options' => array(
                    'route'    => '/application',
                    'defaults' => array(
                        '__NAMESPACE__' => 'Application\Controller',
                        'controller'    => 'Index',
                        'action'        => 'index',
                    ),
                ),
                'may_terminate' => true,
                'child_routes' => array(
                    'default' => array(
                        'type'    => 'Segment',
                        'options' => array(
                            'route'    => '/[:controller[/:action]]',
                            'constraints' => array(
                                'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
                                'action'     => '[a-zA-Z][a-zA-Z0-9_-]*',
                            ),
                            'defaults' => array(
                            ),
                        ),
                    ),
                ),
            ),
        ),
    ),

zendtest \模块\应用程序\视图\布局\ layout.phtml

<?php echo $this->doctype(); ?>

<html lang="en">
    <head>
        <meta charset="utf-8">
        <?php echo $this->headTitle('ZF2 '. $this->translate('Skeleton Application'))->setSeparator(' - ')->setAutoEscape(false) ?>

        <?php echo $this->headMeta()
            ->appendName('viewport', 'width=device-width, initial-scale=1.0')
            ->appendHttpEquiv('X-UA-Compatible', 'IE=edge')
        ?>

        <!-- Le styles -->
        <?php echo $this->headLink(array('rel' => 'shortcut icon', 'type' => 'image/vnd.microsoft.icon', 'href' => $this->basePath() . 'public/img/favicon.ico'))
                        ->prependStylesheet($this->basePath('public/css/style.css'))
                        ->prependStylesheet($this->basePath('public/css/bootstrap-theme.min.css'))
                        ->prependStylesheet($this->basePath('public/css/bootstrap.min.css')) ?>

        <!-- Scripts -->
        <?php echo $this->headScript()
            ->prependFile($this->basePath('public/js/bootstrap.min.js'))
            ->prependFile($this->basePath('public/js/jquery.min.js'))
            ->prependFile($this->basePath('public/js/respond.min.js'), 'text/javascript', array('conditional' => 'lt IE 9',))
            ->prependFile($this->basePath('public/js/html5shiv.js'),   'text/javascript', array('conditional' => 'lt IE 9',))
        ; ?>

    </head>
    <body>

0 个答案:

没有答案