2014-04-02 65 views
0

我現在從Zend Framework 2開始,所以我正在學習如何使用它。我試圖構建一個layout.phtml頁面像波紋管:腳本和樣式表不能在zend框架2中工作

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

<html lang="pt-BR"> 
    <head> 
     <meta charset="utf-8"> 

     <!-- Title Head --> 
     <?php 
     $NAME_APPLICATION = 'Enquete';   
     var_dump($this); 
     echo $this 
       ->headTitle($NAME_APPLICATION) 
       ->setSeparator(' - ') 
       ->setAutoEscape(false) 
     ; 
     ?> 

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

     <!-- Styles --> 
     <?php 
     echo $this 
       ->headLink(array('rel' => 'shortcut icon', 'type' => 'image/vnd.microsoft.icon', 'href' => $this->basePath() . '/img/favicon.ico')) 
       ->prependStylesheet($this->basePath() . '/css/style.css') 
       ->prependStylesheet($this->basePath() . '/css/bootstrap-theme.min.css') 
       ->prependStylesheet($this->basePath() . '/css/bootstrap.min.css') 
     ; 
     ?> 
    </head> 
    <body> 
     <div class="container"> 
      <div class="header"> 
       <ul class="nav nav-pills pull-right"> 
        <li class="active"><a href="#">Início</a></li> 
        <li><a href="#">Sobre</a></li> 
       </ul> 
       <h3 class="text-muted"><?php echo $NAME_APPLICATION; ?></h3> 
      </div> 

      <div class="row marketing"> 
       <?php echo $this->content; ?> 
      </div> 

      <div class="footer"> 
       <p class="muted credit pull-left">Company <a href="">© 2013</a></p> 
       <p class="muted credit pull-right">Desenvolvido por <a href="http://igorrocha.com.br">Igor Rocha</a>.</p> 
      </div> 
     </div> 

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

     echo $this->inlineScript(); 
     ?> 
    </body> 
</html> 

我只有所謂的「民意調查」模塊,但是當我嘗試從訪問:「本地主機/ myproject的/公衆」這個腳本和樣式AREN 「T渲染,看看有什麼appers:

<div class="topo-table"> 
    <a class="btn btn-success" title="Novo"><span class="glyphicon glyphicon-plus"></span></a> 

    <div class="btn-group" title="Quantidades por Página"> 
     <button type="button" class="btn btn-default">005</button> 
     <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown"> 
      <span class="caret"></span> 
     </button> 
     <ul class="dropdown-menu pull-right" style="min-width: 75px" role="menu"> 
      <li class="active"><a href="#">005</a></li> 
      <li><a href="#">010</a></li> 
      <li><a href="#">025</a></li> 
      <li><a href="#">050</a></li> 
      <li><a href="#">100</a></li> 
     </ul> 
    </div> 

    <form class="form-inline pull-right" role="form"> 
     <div class="form-group"> 
      <label class="sr-only" for="localizar">Buscar...</label> 
      <input type="search" class="form-control" id="localizar" placeholder="Bucar..."> 
     </div> 
     <button type="submit" class="btn btn-default"><span class="glyphicon glyphicon-search"></span></button> 
    </form> 
</div> 

<br /> 

<div class="corpo-table"> 
    <table class="table table-striped table-bordered table-hover"> 
     <thead> 
      <tr> 
       <th>#</th> 
       <th>Nome</th> 
       <th>Tel. Principal</th> 
       <th>Tel. Qua.</th> 
       <th>Data Criação</th> 
       <th>Ação</th> 
      </tr> 
     </thead> 

     <tbody> 
          <tr> 
        <td>1</td> 
        <td>Fortaleza Ceará Brasil</td> 
        <td>(085)85858585</td> 
        <td class="text-center">2</td> 
        <td> 

我module.config.php

<?php 

return array(
    # definir e gerenciar controllers 
    'controllers' => array(
     'invokables' => array(
      'HomeController' => 'Enquete\Controller\HomeController' 
     ), 
    ), 

    # definir e gerenciar rotas 
    'router' => array(
     'routes' => array(
      'home' => array(
       'type'  => 'Literal', 
       'options' => array(
        'route' => '/', 
        'defaults' => array(
         'controller' => 'HomeController', 
         'action'  => 'index', 
        ), 
       ), 
      ), 
     ), 
    ), 

    # definir e gerenciar servicos 
    'service_manager' => array(
     'factories' => array(
      #'translator' => 'Zend\I18n\Translator\TranslatorServiceFactory', 
     ), 
    ), 

    # definir e gerenciar layouts, erros, exceptions, doctype base 
    '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', 
      'enquete/home/index' => __DIR__ . '/../view/enquete/home/index.phtml', 
      'error/404'    => __DIR__ . '/../view/error/404.phtml', 
      'error/index'   => __DIR__ . '/../view/error/index.phtml', 
     ), 
     'template_path_stack' => array(
      __DIR__ . '/../view', 
     ), 
    ), 
); 

回答

0

你可以用兩種方法解決這個問題:

  1. 把所有的.css和在主要公共文件夾(這是你的模塊外).js文件,你可以使用這樣的:

    prependFile($this->basePath() . '/css/abc.css') 
    
  2. 您可以派生this module,那麼你可以在你的模塊中創建一個公用文件夾,並將你的.css/.js文件放入其中。

+0

此文件已在公用文件夾內,在我的模塊文件夾之外 –

+0

您是否添加了信息。用於鏈接module.config.php文件中的佈局文件? –

+0

我該怎麼做?能給我看看麼 ? –