2016-08-17 109 views
0

我在同一台服务器上为三个不同的客户端运行相同的应用程序(由CodeIgniter制作)。CodeIgniter:在控制器中查找方法,如果没有,请查看默认控制器

该应用程序大部分是相同的,但每个客户端都有自己的修改(和它自己的子域),但现在任何时候我必须进行一般修改,我必须通过所有三个客户端的应用程序并执行修改。

我想拥有的是:

只部署该应用后,和某种程度的控制那里,如果你去

client1.example.com/method1

该应用程序查找method1在控制器client1.php中,如果找到了method1,则加载它,否则,在控制器中查找method1 default.php

这样,我可以为所有客户端加载来自同一个源的通用方法,然后是特定的控制器为每个客户提供他们特定的方法。

P.S.方法基本相同,但客户的不同需求需要能够对每一个进行大的修改。

任何帮助,将不胜感激。


编辑:

好吧,让我尝试更加清晰。

在wiredesignz Modular Extensions - HMVC中,当您调用index.php/welcome时,它会在默认控制器中查找它。当你加载一个模块并调用index.php/welcome时,它会首先在模块目录中查找它,如果没有找到,它将默认为默认控制器。

如何在没有模块功能的情况下实现这个功能?

+0

你能详细一点?以及如何将其应用于CI。谢谢。 – gvillavizar

+0

在对应用程序进行更改时,您无需以艰难的方式完成任务。您可以使用Git等版本控制软件。 – JobSam

回答

0

好吧好吧......如果我解释你的问题。

假设我有URL的这样的(家是我的默认控制器)

http://stackoverflow.com/home/method_1 # Exist in my controller 
http://stackoverflow.com/home/method_2 # Exist in my controller 
http://stackoverflow.com/home/method_3 # NOT in my controller <--------- 
http://stackoverflow.com/home/method_4 # Exist in my controller 

在上述链接URL 3是不存在的。

随着你的问题,我有一个问题。 如果URL不存在用户如何访问链接?没有人知道你的网址,除非你定义它。用户不会在浏览器中输入网址。好吧,我们会继续。


因此,作为更好的解决方案我得到的是,如果不存在页我们称它为具有压倒一切的404。所以,你可以在routes.php

http://stackoverflow.com/home/method_1 # Valid URL 
http://stackoverflow.com/home/method_2 # Valid URL 
http://stackoverflow.com/home/method_3 # 404 ERROR <--------- 
http://stackoverflow.com/home/method_4 # Valid URL 

使用笨404_overrideapplication/config/routes.php

$route['404_override'] = ''; # set this to your home controller 
0
class defaultcontroller 
{ 
    protected function method1() 
    { 
     //default.php 
    } 
} 



class client1 extends defaultcontroller 
{ 
    public function method1() 
    { 
     //client1.php 
     //if this method existed,it will be executed 
     //or the same method in defaultcontroller will be excuted 
    } 
} 

你可以做同样的事情在client2.php和client3.php