【发布时间】:2011-10-28 03:45:37
【问题描述】:
我想从 Controller 调用函数以使用 Codeigniter 包含到 View 页面中。通常当我打开任何页面时,我会在 Controller 中调用 $this->load->view() 来打开该页面。现在我想将子页面包含到主页中,但它不能在视图中包含任何功能。我尝试包含这样的功能。
<body><? include(site_url().'/login'); ?></body>
<body><? include('/login'); ?></body>
<body><? include('./login'); ?></body>
我可以使用此链接http://localhost/ci_house/index.php/login 打开页面。但是当我打开主页运行我的代码时,它会显示这些错误。
A PHP Error was encountered
Severity: Warning
Message: include(http://localhost/ci_house/index.php/login) [function.include]: failed to open stream: no suitable wrapper could be found
Filename: views/main.php
Line Number: 8
A PHP Error was encountered
Severity: Warning
Message: include() [function.include]: Failed opening 'http://localhost/ci_house/index.php/login' for inclusion (include_path='.;C:\php5\pear')
Filename: views/main.php
Line Number: 8
我想在一页中显示 2 个视图。
function test1()
{ $data['var_for_login_view'] = 'get table1';
$this->load->view('main1',$data);
}
function test2()
{ $data['var_for_login_view'] = 'get table2';
$this->load->view('main2',$data);
}
在views/main.php中:
$this->load->view('test1');
$this->load->view('test2');`
我想表现得像
<body>
include('main1.php');
include('main2.php');
</body>
但我可以在 Codeigniter 中这样显示。
【问题讨论】:
-
你想从一个视图中包含另一个视图吗?
-
是的,示例
function sh_all_post() { $this->load->model('post_model', 'post'); $data['qry_post'] = $this->post->get_all_post(); $this->load->view('sh_all_post_view',$data); } public function main() { $this->load->view('main'); }我想包含这些功能以仅在索引页面中显示。当我打开索引页面时,它必须在索引页面中显示这些功能的页面。
标签: php codeigniter include