douxian7117 2014-01-09 09:28
浏览 26

多个页面由1个控制器控制,视图位于多个位置 - CodeIgniter

Not 100% sure this is possible but was requested by a colleague to make his life easier.

We have an archive of our newsletters that are sent out and the site is in a CodeIgniter framework with a couple of controllers for the different newsletters. The controller is set up as follows:

<?php

class Software1 extends CI_Controller {

    public function index($software1 = 'home') {

        if (!file_exists('../application/views/software1/' . $software1)) {
            // Whoops, we don't have a page for that!
            show_404();
        }
        $this->lang->load('common/menu.php');
        $this->lang->load('common/links.php');
        $this->lang->load('common/footer.php');

        $data['title'] = basename($software1, ".html");

        $this->load->view('templates/common/header', $data);
        $this->load->view('software1/' . $software1, $data);
        $this->load->view('templates/common/footer', $data);
    }
}

So this means that currently the views are pulled from the software1 folder. The email views are labelled December 2013.html, January 2014.html etc. This works fine but my colleague asked if it was at all possible if he could separate put all of 2013 e-mails in a 2013 folder and 2014 in a 2014 folder so it makes his life easier to sort out.

Is it possible to have the controller look in multiple folders for the views or is there any other way I can achieve this so that all of the 2013 would be in software1/2013/Month 2013.html and that 2014 would be in software1/2014/Month 2014.html

Yes I know I could create separate controllers per year but am trying to avoid this and if there is a good way to do this using so if and else then that would be great. If it is not possible then that's fine I will just tell him to upload to one folder and leave it like that but any suggestions would be welcome.

Thanks

EDIT//

Current Folder Structure:

application/
---controllers/
------archive.php
------software1.php
---views/
------Software1/
---------Archive.html
---------January 2013.html
---------Febuary 2013.html
---------March 2013.html
---------April 2013.html
---------May 2013.html
---------June 2013.html
---------July 2013.html
---------August 2013.html
---------September 2013.html
---------October 2013.html
---------November 2013.html
---------December 2013.html
---------January 2014.html

And oviously have to take into account future years as well ie 2015,16,17 etc.

The I need to be able to easily define the urls in the route file currently the outes look like:

$route['(:any)/(:any)/(:any)/(:any)'] = 'Software1/$1/$2/$3/$4';
$route['(:any)/(:any)/(:any)'] = 'Software1/$1/$2/$3';
$route['(:any)/(:any)'] = 'Software1/$1/$2';
$route['(:any)'] = 'Software1/$1';
$route['default_controller'] = 'Software1/index/home.html';
$route['Archive'] = "ArchiveSoftware1/index/Archive.html";
$route['2013/January'] = "Software1/index/January 2013.html";
$route['2013/March'] = "Software1/index/March 2013.html";
$route['2013/May'] = "Software1/index/May 2013.html";
$route['2013/July'] = "Software1/index/July 2013.html";
$route['2013/September'] = "Software1/index/September 2013.html";
$route['2013/November'] = "Software1/index/November 2013.html";
$route['2014/January'] = "Software1/index/January 2014.html";

As it appears my question is about as clear as mud lol hopefully this will help:

So I want the folder structure:

application/
---controllers/
------archive.php
------software1.php
---views/
------Software1/
---------Archive.html
------------2013/
---------------January 2013.html
---------------Febuary 2013.html
---------------March 2013.html
---------------April 2013.html
---------------May 2013.html
---------------June 2013.html
---------------July 2013.html
---------------August 2013.html
---------------September 2013.html
---------------October 2013.html
---------------November 2013.html
---------------December 2013.html
------------2014/
---------------January 2014.html

Each 1 of those views is an individual webpage online the only common things they have is they are sharing the header and footer files. What I am trying to do it have 1 controller that goes if goes to url.net/2014/January will display the info in the January 2014.html view file (as I have said I have this working if the subfolders 2013 and 2014 are not there ie everything in the software1 folder and I can have this working if I use multiple controllers ie 1 for 2013 and 1 for 2014 etc. however I am trying to have it so I can do this in 1 controller that so it will look at any of the subfolders to find the correct file to display as defined by the route file.

As I said I have no idea if this is actually do able but hopefully someone can understand what I am trying to acheive and give me some way of doing this :)

  • 写回答

1条回答 默认 最新

  • douji4948 2014-01-09 10:18
    关注

    In my view page One folder is modules. That contains different folders. One of that is fault.And that again contains booking,add,deleted folders. And each of these contains different php files.

    We can write:

    $this->load->view('modules/fault/booking/booking');
    $this->load->view('modules/fault/booking/schedule');
    $this->load->view('modules/fault/booking/delete');
    
    $this->load->view('modules/fault/add/file');
    $this->load->view('modules/fault/add/add');
    $this->load->view('modules/fault/add/edit');
    $this->load->view('modules/fault/add/delete');
    

    etc...

    评论

报告相同问题?

悬赏问题

  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?