ThinkPHP 3.2.3的 R 方法

R方法是可以调用其他的Controller中的方法,
例如
我想在Mit/DebugController.class.php中调用Foo/DoController.class.php中的share方法,
需要在Mit/DebugController.class.php中写成

$pass = R("Foo/Do/share",array("26121"));
new Foo\Controller\DoController

这里是同一个项目底下的不同分类(Foo和Mit)。
但是需要注意几点,

  1. 如果你定义了Mit/Conf底下定义的DB_PREFIX和在Foo/Conf不同,则在Foo/DoController.class.php的方法中需要重新动态定义C('DB_PREFIX','ofo');Foo底下的配置。简单说就是,** 你用R()调用的方法使用的配置是当前的分类下的,而不是它原来的配置**,需要小心;

  2. R()方法的第3个参数是指定** layer **,默认的是DEFAULT_C_LAYERController。如果你指定了其他的layer,例如Foo/ConfigEvent.class.php这,这里需要指定为Event

  3. 如果你定义了ACTION_SUFFIX也就是可以调用的方法的后缀,你必须要保证这里的DoController类中的sharepublic而且加了ACTION_SUFFIX

  4. 具体的你可以打开ThinkPHP的log,在RunTime/Logs/Mit/2016.07.19.log中查看具体的错误。

ThinkPHP的单字母方法在ThinkPHP/Common/functions.php定义的,具体可以查看那里。

Reference:

  1. http://www.thinkphp.cn/document/134.html
  2. http://www.thinkphp.cn/topic/4723.html
  3. http://www.thinkphp.cn/document/309.html
posted @ 2016-07-17 18:52  乌祁班岚图  阅读(1074)  评论(0编辑  收藏  举报