codeigniter包括视图中的公共文件

Ale*_*eri 17 php codeigniter

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

require(base_url().'application/libraries/common.php'); //I have tried also include
Run Code Online (Sandbox Code Playgroud)

这回复了我这个错误:

A PHP Error was encountered

Severity: Warning

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

我要去我的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
Run Code Online (Sandbox Code Playgroud)

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

xbo*_*nez 34

将其拉入您想要的任何视图中$this->load->view('common');您可以从控制器或视图中包含其他视图.

例1

your_controller.php

public function index() {
   $this->load->view('homepage');
}
Run Code Online (Sandbox Code Playgroud)

意见/ homepage.php

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

<body>
  <!-- html -->
</body>
Run Code Online (Sandbox Code Playgroud)

例2

your_controller.php

public function index() {
  $this->load->view('common');
  $this->load->view('homepage');
}
Run Code Online (Sandbox Code Playgroud)