dongxing2302 2013-11-07 18:19
浏览 100

如何设置PHP控制器

Im giving support to an already deployed php application, but the way it works is new to me, and I have no idea how it does what it does.

Basically, a php method is called using a path-like syntax to retrieve data, for example:

<?php
// .....
$json = Request("http://_server/myfolder/abc/default/mymethod?data=something");
// Now $json var has some information.
?>

The odd thing is how methods are structured. Up to folder 'myfolder' physical path exists in linux 'server', you know ".../apache/htdocs/myfolder/" but thats IT. Further than that, physical location of code is within a different folder structure where default/mymethod matches NO folders at all.

By digging deeper, I found that mymethod corresponds to the PHP method located in:

apache/htdocs/myfolder/protected/modules/abc/controllers/defaultcontroller.php

And inside defaultcontroller.php there is something like this:

<?php
// ....
Class DefaultController {
    // ....
    Public Function actionmymethod { // Notice the name of mymethod has 'action'
        // more code
        return $response;
    }
}
?>

Im 100% sure that method is fired when running the Request call, but my I dont know how it is done.

My question is:

How the setup of this is done? There must be some place where you relate:

"http://_server/myfolder/abc/default/mymethod" with "actionmethod"

but where and how?

I need to make a copy of this running, so I can call my copy with something like this:

"http://_server/FOLDERCOPY/myfolder/abc/default/mymethod" 

I already made a copy to the new structure, but when calling it, server cant find the new method/path :(

EDIT*** I found this in htaccess located at /myfolder/

RewriteEngine on
RewriteBase /myfolder/ 

# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d 

# otherwise forward it to index.php
RewriteRule . index.php

I modified the copy inside /FOLDERCOPY/myfolder, but it seems is not working :(

RewriteEngine on
RewriteBase /FOLDERCOPY/myfolder/ 

# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d 

# otherwise forward it to index.php
RewriteRule . index.php

Thanks

  • 写回答

1条回答 默认 最新

  • douduandiao1368 2013-11-07 18:46
    关注

    Not every url is mapped 1:1 to the server's filesystem.

    Apparently, there should be a php script inside .../apache/htdocs/myfolder/, most probably an index.php. There should also be some rewrite rules, probably in a .htaccess file, that translate urls under http://_server/myfolder to that script, tranforming the remaining part to parameters (either a query_string or a path_info).

    From this point on, php takes over. The structure implies the existence of an MVC framework. This framework appears to support modules, one of them being abc, whose default controller's mymethod method is called to handle the request. So the url structure is like this:

    http://server/site/module/controller/method?params
    

    Look for a config file under .../apache/htdocs/myfolder/ (config.php?). It will contain rules as to the modules' location and the mappings (routing) to controllers. Then again, there may be a global site config, as well as one for each module...

    评论

报告相同问题?

悬赏问题

  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥85 maple软件,solve求反函数,出现rootof怎么办?
  • ¥15 求chat4.0解答一道线性规划题,用lingo编程运行,第一问要求写出数学模型和lingo语言编程模型,第二问第三问解答就行,我的ddl要到了谁来求了
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题