【问题标题】:PHP code inside layout file not executed布局文件中的 PHP 代码未执行
【发布时间】:2018-03-15 16:41:30
【问题描述】:

我在布局文件 (default.htm) 顶部定义的一些 PHP 代码存在问题,但该代码无法执行。 它只是逐字打印在页面上。 布局文件是插件的默认布局。 这是源文件(default.htm):

title = "default"
==
<?

use Config;

function onStart() {
    $this['select2_Api_Url'] = Config::get('tudordanes.select2::select2_Api_Url');
}

?>
==
<form action="#" method="POST">
    <div id='my-selects' >
        <label for='select-codes'>Code de loi:</label>
        <select id='select-codes' class='select2' name='select-codes'>
            <option value="">Choisir un code</option>
        </select>
        <label for='select-articles'>Numero:</label>
        <select id='select-articles' name='select-articles'>
            <option value="">Numero d'article</option>
        </select>
    </div>
</form>

{% put scripts %}
<script type="text/javascript">
    $(document).ready(function() {
        console.log('ready!');
        console.log('{{ cfg_API_URL }}');        
</script>    
{% endput %}

【问题讨论】:

  • 您是直接通过http://localhost/laravel/layouts/default.htm等url访问布局文件吗?如果没有,那么如何访问这个布局文件?
  • 这个文件的路径是\plugins\tudordanes\select2\components\select2\default.htm。这是select2插件定义的select2组件的布局文件。
  • 如果您在 Web 浏览器中访问 C:\xampp\htdocs\october\plugins\tudordanes\select2\components\select2\default.htm,那么它只不过是一个普通的 HTM 文件,因此永远不会调用 PHP。您需要设置一个 Web 服务器,以便执行 PHP。
  • 嗯,我不确定这个..文件被 OctoberCMS 正确解析,除了 PHP 部分被忽略。这就是问题所在!

标签: php laravel octobercms


【解决方案1】:

实际上,您的 default.htm 文件位于“tudordanes”插件中名为“select2”的组件中。规则是您不能访问组件中的 PHP 代码部分。请参考Building components instructions 以获得更好的解释。

根据相关代码,您可以在 Select2.php 文件中定义 onRun() 函数。

use Config;
public function onRun()
{
    $this->page['select2_Api_Url'] = Config::get('tudordanes.select2::select2_Api_Url');
}

【讨论】:

  • 感谢您的回答!我不知道文档中到底是在哪里说明的,但没关系..
【解决方案2】:

您确定您有并且未注释

AddType application/x-httpd-php .htm

在您的httpd.conf 文件中?

“短标签”是一个坏习惯,如果你真的需要使用它们,请确保你拥有并且未注释:

short_open_tag=On

在你的php.ini

【讨论】:

  • October CMS 使用在 .htm 文件上定义的模板,这些模板稍后会转换为 PHP 代码……或类似的东西……因此无需将 apache 配置为 .htm 处理为 php 代码……跨度>
  • 这个问题与 httpd.conf 设置无关。请看正确答案。
猜你喜欢
  • 1970-01-01
  • 2017-07-25
  • 2013-12-14
  • 1970-01-01
  • 2014-04-24
  • 1970-01-01
  • 2019-07-23
  • 1970-01-01
相关资源
最近更新 更多