我想实现一个新的模块到一个网站,这是与CI。我是一个绝对的CI新手,我不知道如何创建控制器和视图文件。我需要将新内容加载到当前站点的iframe中。到目前为止,我有:
控制器:
class Module extends Controller {
function __construct() {
parent::Controller();
}
function index() {
$this->common->loadView('module/module');
}
}
视图:
<iframe src="/new_module/index.php" width="100%" height="100%" scrolling="NO" frameborder="0" >An iframe capable browser is required to view this web site.</iframe>
路线:
$route['module/(:any)'] = "module/$1";
网站结构:
resources/
system/
....
new_module/
new_module/index.php
new_module/page1.php
new_module/page2.php
链接应为:
http://mydomain.com/module/page1
http://mydomain.com/module/page2
链接在iframe之外,内容应该在iframe内加载。因此,应该动态更改iframe src。
显然,它不起作用。有更有CI经验的人能告诉我怎么做吗应该做什么?
谢谢!
要动态更改框架,只需将链接的目标设置为iframe:
<a href="/pages/page/1" target="targetFrame">Page 1</a>
<iframe id="targetFrame" src="" width="100%" height="100%" scrolling="NO" frameborder="0" ></iframe>
据我所知,默认情况下,Codeigniter没有"模块"。除非您正在使用CMS或构建在CI之上的诸如此类的东西,在这种情况下您需要指定它。
否则,只要正确地使用控制器就可以得到你想要的。
class Pages extends Controller{
public function page($id='')
{
switch $id{
case 1:
$data['pageData']='foo';
break;
...
}
$this->load->view('page_view',$data);
}
}