• <i id='eA3UU'><tr id='eA3UU'><dt id='eA3UU'><q id='eA3UU'><span id='eA3UU'><b id='eA3UU'><form id='eA3UU'><ins id='eA3UU'></ins><ul id='eA3UU'></ul><sub id='eA3UU'></sub></form><legend id='eA3UU'></legend><bdo id='eA3UU'><pre id='eA3UU'><center id='eA3UU'></center></pre></bdo></b><th id='eA3UU'></th></span></q></dt></tr></i><div id='eA3UU'><tfoot id='eA3UU'></tfoot><dl id='eA3UU'><fieldset id='eA3UU'></fieldset></dl></div>

    <legend id='eA3UU'><style id='eA3UU'><dir id='eA3UU'><q id='eA3UU'></q></dir></style></legend>

    <tfoot id='eA3UU'></tfoot>

    <small id='eA3UU'></small><noframes id='eA3UU'>

        <bdo id='eA3UU'></bdo><ul id='eA3UU'></ul>
      1. 使用 Laravel 框架包含 PHP 文件

        Including PHP files with Laravel framework(使用 Laravel 框架包含 PHP 文件)

              <tbody id='V5daI'></tbody>
            <i id='V5daI'><tr id='V5daI'><dt id='V5daI'><q id='V5daI'><span id='V5daI'><b id='V5daI'><form id='V5daI'><ins id='V5daI'></ins><ul id='V5daI'></ul><sub id='V5daI'></sub></form><legend id='V5daI'></legend><bdo id='V5daI'><pre id='V5daI'><center id='V5daI'></center></pre></bdo></b><th id='V5daI'></th></span></q></dt></tr></i><div id='V5daI'><tfoot id='V5daI'></tfoot><dl id='V5daI'><fieldset id='V5daI'></fieldset></dl></div>
            • <tfoot id='V5daI'></tfoot>

              <legend id='V5daI'><style id='V5daI'><dir id='V5daI'><q id='V5daI'></q></dir></style></legend>

              1. <small id='V5daI'></small><noframes id='V5daI'>

                • <bdo id='V5daI'></bdo><ul id='V5daI'></ul>
                  本文介绍了使用 Laravel 框架包含 PHP 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试将 php 脚本包含"到我的一个视图 (landing.blade.php) 中.

                  I am trying to "include" a php script into one of my views (landing.blade.php).

                  脚本在:

                  /laravel-master/public/assets/scripts/config.php
                  

                  当我尝试在视图中包含此代码时:

                  When I try to include this code in the view:

                  <?php include_once('/assets/scripts/config.php'); ?>
                  

                  我得到错误:include_once(/assets/scripts/config.php): failed to open stream: No such file or directory

                  这是在本地主机上使用 MAMP.我不确定是否需要在 Laravel 4 中使用一组不同的规则来包含一个 php 文件.感谢您的帮助!

                  This is on localhost using MAMP. I'm not sure if there is a different set of rules I need to use with Laravel 4 to include a php file. Thank you for your help!

                  推荐答案

                  首先,不建议您将 PHP 文件保存在 public 目录中,它们应该保存在 中app 文件夹.我建议您在 app 中创建一个文件夹,例如 includes 并将您的文件放在那里.然后,包含它,执行以下操作:

                  First, it's not really recommended that you keep your PHP files in the public directory, they should be kept inside the app folder. I'd suggest you create a folder inside app, something like includes and put your files there. Then, you include it, do:

                  include(app_path().'/includes/config.php');
                  

                  虽然,由于您似乎正在尝试加载一些配置文件,我还是建议您查看 Laravel 自己处理配置的方式.例如,如果你在 app/config 文件夹中创建了一个 myapp.php 文件,Laravel 会自动为你处理它,只要你有一些关键 -值对,像这样:

                  Although, since it looks like you're trying to load some configuration files, I'd recommend you also check out Laravel's own way of handling configurations. For instance, if you created a myapp.php file inside the app/config folder, Laravel would handle it automatically for you, as long as you'd have some key-value pairs, like this:

                  <?php
                  
                  return [
                      'name'     => 'Raphael',
                      'gorgeous' => true
                  ];
                  

                  然后您可以使用 Config 类检索这些值:

                  You could then retrieve these values using the Config class:

                  Config::get('myapp.name'); // Raphael
                  

                  这是一个更好的解决方案,因为您还可以利用 Laravel 的 环境配置.

                  This is a better solution because you can also take advantage of Laravel's environment configuration.

                  这篇关于使用 Laravel 框架包含 PHP 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Laravel 4 - Connect to other database(Laravel 4 - 连接到其他数据库)
                  Call external API function from controller, LARAVEL 4(从控制器调用外部 API 函数,LARAVEL 4)
                  Empty string instead of null values Eloquent(空字符串而不是空值 Eloquent)
                  quot;laravel.logquot; could not be opened: failed to open stream(“laravel.log无法打开:无法打开流)
                  Displaying the Error Messages in Laravel after being Redirected from controller(从控制器重定向后在 Laravel 中显示错误消息)
                  Laravel Creating Dynamic Routes to controllers from Mysql database(Laravel 从 Mysql 数据库创建到控制器的动态路由)

                    <i id='Lt0Pj'><tr id='Lt0Pj'><dt id='Lt0Pj'><q id='Lt0Pj'><span id='Lt0Pj'><b id='Lt0Pj'><form id='Lt0Pj'><ins id='Lt0Pj'></ins><ul id='Lt0Pj'></ul><sub id='Lt0Pj'></sub></form><legend id='Lt0Pj'></legend><bdo id='Lt0Pj'><pre id='Lt0Pj'><center id='Lt0Pj'></center></pre></bdo></b><th id='Lt0Pj'></th></span></q></dt></tr></i><div id='Lt0Pj'><tfoot id='Lt0Pj'></tfoot><dl id='Lt0Pj'><fieldset id='Lt0Pj'></fieldset></dl></div>
                      <tfoot id='Lt0Pj'></tfoot>

                      <small id='Lt0Pj'></small><noframes id='Lt0Pj'>

                        <bdo id='Lt0Pj'></bdo><ul id='Lt0Pj'></ul>

                            <tbody id='Lt0Pj'></tbody>
                          <legend id='Lt0Pj'><style id='Lt0Pj'><dir id='Lt0Pj'><q id='Lt0Pj'></q></dir></style></legend>