gpt4 book ai didi

php - codeigniter 在 View 中包含公共(public)文件

转载 作者:IT王子 更新时间:2023-10-29 00:11:03 26 4
gpt4 key购买 nike

大家好,我有一个用 codeigniter 开发的网站,我想将我在许多页面中使用的一些 javascript/PHP 函数存储到一个名为 common.php 的文件中。我试过这种模式:

require(base_url().'application/libraries/common.php'); //I have tried also include

这会返回这个错误:

A PHP Error was encountered

Severity: Warning

Message: require() [function.require]: http:// wrapper is disabled in the server configuration by allow_url_include=0

我要去我的 php.ini 并打开 allow_url_include,重新启动 apache,当我尝试加载页面时,现在返回这个错误:

A PHP Error was encountered

Severity: Warning

Message: require() [function.require]: http:// wrapper is disabled in the server configuration by allow_url_include=0

Filename: backend/hotel_view.php

Line Number: 6

A PHP Error was encountered

Severity: Warning

Message: require(http://demo.webanddesign.it/public/klikkahotel.com/application/libraries/common.php) [function.require]: failed to open stream: no suitable wrapper could be found

Filename: backend/hotel_view.php

Line Number: 6


Fatal error: require() [function.require]: Failed opening required 'http://demo.webanddesign.it/public/klikkahotel.com/application/libraries/common.php' (include_path='.:/usr/share/php:/usr/share/pear') in /var/www/public/klikkahotel.com/application/views/backend/hotel_view.php on line 6

如何将一个简单的文件包含到我的页面中?

最佳答案

使用 $this->load->view('common'); 将其拉入您想要的任何 View 中;您可以从 Controller 或 View 中包含其他 View 。

示例 1

你的 Controller .php

public function index() {
$this->load->view('homepage');
}

views/homepage.php

<?php
$this->load->view('common');
?>

<body>
<!-- html -->
</body>

示例 2

你的 Controller .php

public function index() {
$this->load->view('common');
$this->load->view('homepage');
}

关于php - codeigniter 在 View 中包含公共(public)文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16446242/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com