2017-06-21 52 views
0

我的文件结构如下:在一根树枝模板加载js文件不能在公用文件夹

---public(Documentroot folder, where all my css,js, images loads from) 
---models 
---modules {all my modules customer, db_management e.t.c) 
---scripts 
    |---ivr_builder 
    |------ui-bootstrap-tpls-0.2.js 
--twig_templates {All my ta} 
    |---layout.twig 

在我的index.php文件,我有这样的:

use \Psr\Http\Message\ServerRequestInterface as Request; 
    use \Psr\Http\Message\ResponseInterface as Response; 

    require '../vendor/autoload.php'; 
    spl_autoload_register(function ($classname) { 
     require "../models/" . $classname . ".php"; 
    }); 

    $config['displayErrorDetails'] = false; 
    $app = new \Slim\App(["settings" => $config]); 
    $container = $app->getContainer(); 
    // Register component on container 
    $container['view'] = function ($container) { 
     $view = new \Slim\Views\Twig(
      '/var/www/html/ivr/twig_templates', ['cache' => false]); 


     $env = $view->getEnvironment(); 
      $lexer = new Twig_Lexer($env, array(
      'tag_comment' => array('{#', '#}'), 
      'tag_block'  => array('{%', '%}'), 
      'tag_variable' => array('[[', ']]'), 
      'interpolation' => array('#{', '}'), 
     )); 
     $env->setLexer($lexer); 
     $loader = new \ Twig_Loader_Filesystem('ivr/scripts/ivr_builder/ui-bootstrap-tpls-0.13.4.js'); 
     $env->getLoader(); 



     return $view; 
    }; 

然后在我的浏览器,我得到这个错误:

Name       | Status 
---------------------------- | ------ 
angular-aside.js    | 200 
jquery.js     | 200 
ui-bootstrap-tpls-0.1.3.4.js | 500 

我layout.swig头看起来是这样的:

<meta http-equiv="Content-Type" content="text/html" charset="iso-8859-1"> 
<meta http-equiv="X-UA-Compatible" content="IE=edge"> 
<meta name="viewport" content="width=device-width, initial-scale=1"> 
{% if page_title is defined and page_title is not null ? page_title: 'Log in' %} 
{% endif %} 
<link rel='stylesheet' href='/css/bootstrap.css'/> 
<link rel='stylesheet' href='/js/libraries/angular-aside/angular-aside.css'/> 
<link rel="stylesheet" href="/js/libraries/angular-notify-master/styles/css/angular-notify-texture.css" id="notifyTheme"> 
<link rel='stylesheet' href='/css/ivr_builder.css'/> 
<link rel="stylesheet" type="text/css" href="/css/custom.css"> 
<script type="application/javascript" src="/js/libraries/angular.js"></script> 
<script type="application/javascript" src="/js/libraries/angular-animate.min.js"></script> 
<script type="application/javascript" src="/scripts/ivr_builder/ui-bootstrap-tpls-0.13.4.js"></script> 

<script type="application/javascript" src="/js/libraries/angular-aside/angular-aside.js"></script> 
<script type="application/javascript" src="/js/libraries/angular-notify-master/scripts/dist/angular-notify.js"></script> 
<script type="application/javascript" src="/js/jquery-ui-1.11.4/external/jquery/jquery.js"></script> 
[[top_bar]] 

请有关如何为什么它不能在浏览器中加载请任何建议。

回答

0

我可以轻松地使用xsendfile加载它:

发送文件 发送带有xsendfile文件非常简单:

<?php 
//We want to force a download box with the filename hello.txt 
header('Content-Disposition: attachment;filename=hello.txt'); 


//File is located at /home/username/hello.txt 
header('X-Sendfile: /home/username/hello.txt'); 

你可以省略第一个头部,在这种情况下,浏览器将不必须显示一个下载文件对话框。另外,X-Sendfile标题不会显示在用户的浏览器中,并且他们永远不会看到他们收到的文件的真实位置。

您不需要发送Content-Length标头,因为Apache会为您处理这个问题。也发现了这个在斯利姆:

XSendFile On 
XSendFilePath "/path/to/directory/containing/js/files" 

而在你的苗条申请途径回调,使用绝对路径设置X-SENDFILE头上面指定的文件路径中的文件:

$app->get('/get-file', function() use ($app) { 
    $res = $app->response(); 
    $res['X-SendFile'] = '/path/to/directory/containing/js/files/foo.js'; 
}); 
+0

我然而,我很惊讶我不能用slim来加载它 – Raphael

+0

所以我打算给这个镜头: XSendFile在 XSendFilePath“/ path/to/directory/contained/js/files” 而在你的Slim应用程序中,路由回调,请在上面指定的文件路径中将X-SendFile标头的绝对路径设置为一个文件: $ app-> get('/ get-file',function()use($ app){ $ res = $ app-> response(); $ res ['X-SendFile'] ='/path/to/directory/containing/js/files/foo.js'; }); – Raphael