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