我刚刚毕业,我即将完成我的网络投资组合。在我的学生作品集不再托管之前,我想将我的一些学校项目转换为CodeIgniter。我想知道是否可以将项目的视图文件夹嵌套在父视图文件夹中,并在浪费我太多时间之前使用单个控制器对其进行操作。
以下是视图的文件夹/文件结构的示例。
视图/ NWTC
nwtc
|
+---website-reviews
| |
| +---page1.php
| +---page2.php
| +---page3.php
| +---page4.php
| +---page5.php
| +---page6.php
|
+---emerging-technology
| |
| +---page1.php
|
+---website-design
| |
| +---page1.php
| +---page2.php
| +---page3.php
| +---page4.php
| +---page5.php
| +---page6.php
|
+---index.php // <--- Project landing page
mysite.com/nwtc/$project/$page
控制器/ Nwtc.php
<?php
class Nwtc extends CI_Controller {
public function index()
{
$data['title'] = 'NWTC Projects';
$data['description'] = '';
$this->load->view('templates/nwtc_header', $data);
$this->load->view('nwtc/index', $data);
$this->load->view('templates/nwtc_footer');
}
public function view($project, $page) // <--- Total Guess
{
if ( ! file_exists(APPPATH.'views/nwtc/'.$project.'/'.$page.'.php'))
{
show_404();
}
$data['title'] = ucwords(str_replace("-"," ",$project)).' '.ucfirst($page);
$data['assets'] = $project; // Project-specific css/js filenames
$data['description'] = array(
'website-reviews' => "",
'emerging-technology' => "",
'website-design' => ""
);
$this->load->view('nwtc/'.$project.'/'.$page, $data); // <--- I'll be amazed if this works
}
}
答案 0 :(得分:1)
是的,可以使用您的代码加载页面
public function view($project, $page)
{
//here $project argument stands for sub folder name
//eg:$project = 'website-reviews',$page = 'page1',then we can load page1.php file
// do the operations
$this->load->view('nwtc/'.$project.'/'.$page, $data);
}
在我看来,您的代码不需要任何更改
答案 1 :(得分:1)
是的,可以加载您的视图。如果你的文件存在,它将加载否则会引发错误。
public function view($project='', $page='')
{
if($project !='' && $page !='')
{
$this->load->view('nwtc/'.$project.'/'.$page, $data);
}
}