Hello everybody,
I’m new to Joomla! To php and to web programming and design, after learning some basics on html/css, php/MySQL, I wanted to know how Joomla! works and how information is gathered from different sources in Joomla! and displayed to the user (data flow), I was looking for an easy and quick way to understand that, I googled, searched in Joomla developer site, forum, unfortunately couldn’t find my way inside the huge stack of docs out there, so I decided to cut it short and jump directly into the core code of Joomla!, it was an exciting trip, and I wanted to share this experience with you, so jump with me in the car and let’s go for the ride!!
What you need:
- Basic knowledge on html, php and oop (object oriented programming)
- Good text editor with php syntax coloring (I use Komodo)
- Php manual (from here)
- Joomla! Framework API documentation (from here)
- Fresh Joomla! 1.5 installation in your local server with default settings and sample data.
As we move along this ride we’ll find lots of intersections leading to multiple paths, we won’t choose the very specific paths instead we’ll take say the “most used” path and continue driving.
Parking brake is off...get ready!!
STEP 1:
Open your joomla site in your browser
Open the index.php in your text editor (you’ll find it in the root folder of Joomla! this folder will be the reference for our future file and path referring)
Take a general look at it…
Some defines, includes, and other bizarre class functions!! and at the end there is an echo statement, try to comment it…refresh your browser…page displays nothing! So now we need to explore this echo statement, uncomment it and add this line above it:
Code: Select all
echo "STEP 1: Exploring: JResponse::toString(\$mainframe->getCfg('gzip'))<br/><br/>";
Let’s go to the API doc to look for JResponse::toString()
(alternatively you can use this site to search for classes, functions, variables… in Joomla framework)
Select Joomla-Framework from the drop down list, Element index, letter J and click on JResponse… read its description…where it is located(Note: folder “joomla” is inside “libraries”)… and take a general look at its “Method Summary” (from now on we’ll refer to this procedure by: examine the class…)
Now click on method toString from “Method Summary”…read its description, arguments, return value etc …(we’ll refer to this procedure by: examine the method…)
It states that the job of this method is sending headers and returning a string, we need to know which headers are sent and more important which string it returns! As this string would be the whole html of our page. So now we need to explore in depth this method, but before that :
Let’s take a look at the headers sent to the browser, you remember a method called getHeaders() when you examined the class JResponse don’t you! Let’s try using it…replace this code:
Code: Select all
echo "STEP 1: Exploring: JResponse::toString(\$mainframe->getCfg('gzip'))<br/><br/>";
echo JResponse::toString($mainframe->getCfg('gzip'));
Code: Select all
$site_index_page_html = JResponse::toString($mainframe->getCfg('gzip'));
echo "<span class='componentheading'>STEP 1: Exploring: JResponse::toString(\$mainframe->getCfg('gzip'))</span><br/><br/>";
echo "<b>All sent headers are: </b>"; print_r(headers_list()); echo "<br/><br/>";
echo "<b>Headers sent by Joomla are: </b>"; print_r(JResponse::getHeaders()); echo "<br/><br/>";
echo "( Note: for a better viewing of arrays, look at the page source (Ctrl+u in firefox) )<br/><br/>";
echo $site_index_page_html;
Add this code before echoing $site_index_page_html:
Code: Select all
echo "<b>\$mainframe->getCfg('gzip') is: </b>"; var_dump($mainframe->getCfg('gzip')); echo "<br/>";
As this post is getting lengthy, we'll stop here and continue on another post where we'll discuss the following points:
- investigating source code of "toString()"
- You can see that our index.php is getting messy with our html echoing, to avoid this (in index.php and other files) we'll build a simple class in a separate file to handle that echoing, this class will be converted later on to a module that will represent our learning (and in the same time debugging) tool
Waiting for your feedback and comments, see u in part 2...
Links : A beginner diving into Joomla! core!! : Part 1 Part 2