Store
Community Documentation

v3 Knowledgebase

From page to php: How to find specific code?

Lets suppose you want to emulate or customize or reuse the behavior of an existing page or section in a phpfox page. The first thing to notice is the module, this is taken from the url, for example:
http://domain.com/group/group1/
and
http://domain.com/index.php?do=/group/group1/

both point to the group module (this url would show you the group named "Group1").

Lets suppose that we want to customize the Basic Info in this group. We know the code is in the group module but where and how to find it?

The first thought may be to go to the controller that displays one specific group, after all the part that I am seeing and want to customize is in one specific group. So we open the template file /module/group/template/default/controller/view.html.php
(How did I know it was this controller? well it makes sense since the other controller template are: add, category, forum, index, redirect and secret).
Just to make sure we are in the right controller I edit it and add a specific word that stands out, then refresh the page and see if that word (or html code if you want) shows up. It did so I know I am in the right file, but I can't find anything in this file that mentions the Basic Info.

So we figure out that its not part of the controller, then it must be a block, so we go to the AdminCP -> CMS -> Blocks -> Manage Blocks and click on the controller group.view, we see all the blocks that are displayed when viewing a group. By looking at the list of blocks there is one that seems suggestive, the group::info, so we open the template file for the group::info block (/module/group/template/default/block/info.html.php) and again add some text or html code that helps us identify this file in the final page. Refresh the page and confirm that this is the file, great! Now we are sure which block is the one we are acting on.

Lets suppose that we want to learn which specific php function is being called here to get the members count, just to make it more interesting. So we see the template file and run into this html code:
HTML:
<span id="js_group_member_count">{$aGroup.total_member}</span>

(if in doubt add more code/text around it to make sure this is the variable that populates this part).
So we know that we need to find where are we telling the template to define the variable $aGroup, first choice is to go to the php file that controls this template: /module/group/include/component/block/info.class.php

but when we open it we find the only assignments here are not related to the $aGroup variable. But wait, this block is inside a controller, so lets check the controller php file /module/group/include/component/controller/view.class.php and here around line 116 we find
PHP:
->assign(array(
                    
'aGroup' => $aGroup

Eureka! it is the controller the one setting the variable aGroup, so now we need to find where are we defining $aGroup and that takes us (in this same file) to line 29:
PHP:
if (!($aGroup Phpfox::getService('group')->getGroup($sGroup))) 

Now we see that it is the service "group" the one getting the group in the function getGroup.
If you open this file (/module/group/include/service/group.class.php) and look for the function getGroup you will see its basically a database call, so the field "total_member" is a field in the table phpfox_group!

At this point you now all the files needed to customize the Basic Info block and as you keep digging in phpfox code you will get more and more acquainted with the pieces of code that handle specific sections and actions.