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...

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度