用户
 找回密码
 入住 CI 中国社区
搜索
查看: 1828|回复: 2
收起左侧

[版本 4.x] 拆解html技巧?

[复制链接]
发表于 2019-8-30 10:01:40 | 显示全部楼层 |阅读模式
有數十支php的html結構如下


<body>
<section></section>
<nav></nav>
<section></section>
...

</body>

其中<nav></nav>是共用部份,
而nav裡頭的選單內容也使用到php的樣板語法<?php xxxx ?>
我把內容裝到另一支nav.php,放在view/common/nav.php

請教依照 https://codeigniter4.github.io/userguide/outgoing/index.html
希望從這邊安插code

<body>
<section></section>
安插code進來
<section></section>
...

</body>
保留 html完整度,


不使用 include,應該怎麼做會最好






发表于 2019-9-2 11:50:45 | 显示全部楼层
为什么不使用 include 呢?
 楼主| 发表于 2019-9-4 12:31:50 | 显示全部楼层
因為我自己的想法是

第一點,
CI4的base_url被強迫使用url格式,
不像ci3還可使用檔案路徑替換,
一但使用 include base_url,會違反allow_url_include=0 php安全性規則,不能使用。

第二點,
假使直接在樣版寫 include 絕對檔案路徑.檔名,
一旦部屬到其他主機時的修改就很囉嗦,
實不妥當。

第三點,
使用相對路徑,
我測試皆失敗,failed to open stream: No such file or directory,
不知道CI4該怎麼做。

請教hex,我應該怎麼做?

PHP复制代码
/*
        |--------------------------------------------------------------------------
        | Base Site URL
        |--------------------------------------------------------------------------
        |
        | URL to your CodeIgniter root. Typically this will be your base URL,
        | WITH a trailing slash:
        |
        |       http://example.com/
        |
        | If this is not set then CodeIgniter will try guess the protocol, domain
        | and path to your installation. However, you should always configure this
        | explicitly and never rely on auto-guessing, especially in production
        | environments.
        |
        */

        public $baseURL = 'http://127.0.0.1/myproject/';
复制代码

本版积分规则