Extending Firebug Database Profiler

Well, as of late I’m a bit obsessed with logging, profiling and other utility tools which help me to see what I’m doing needlessly and how I can improve performance. In my previous posts, I had mentioned in keeping logs with FirePHP and database profiling with FirePHP. Now I got an idea that wouldn’t be great to see what the sql queries had returned just looking on the profiler log. By this way I would have checked whether or not the query was working right or wrong and other kind of cool stuff.

Continue reading Extending Firebug Database Profiler

Zend Database Profiler and Firebug/FirePHP

For some days, I’m looking around for logging and debugging options I can use for some projects of mine and projects in the work. Yesterday I had stumbled upon the Zend_Log and FirePHP duo and they worked perfectly well. The best of course was the log level option disabling logs which were not that important.

Continue reading Zend Database Profiler and Firebug/FirePHP

Keep your logs with FirePHP

If you are a web developer, It’s not possible that you did not heard of Firebug. One of the greatest extensions written for Firefox! In the recent days I finally found some spare time to handle logging for my CMS framework Boop. I had Zend Framework and I decided to use Zend_Log which had a great feature like sending your logs to FirePHP, an extension for Firebug.

Continue reading Keep your logs with FirePHP

Writing You Own PHPUnit Listener

Well, in the company, Parkyeri, we have restarted to a crusade to cover all the code lines we had by writing unit tests.

As a PHP Developer, I’m taking the part where I have to write PHPUnit, the xUnit family which is developed for the PHP language. I had used it in the first version for a while, but I had seen that it had reached to the 3rd version. As I’m someone who likes to use the latest things and demos, I tried the latest version and migrated all the first version unit tests to the latest version, which was surprisingly, very easy. You just have to change some class inheritance, delete some constructors, and you are nearly done.

Continue reading Writing You Own PHPUnit Listener

Netbeans 6.5 and PHP Support

Well, a new feature has been added to Netbeans from now on. With the new release of 6.5, PHP support has been added and now we have an IDE which fully support code complete (including your own classes, methods, functions and variables), PHPDoc abilities(showing doc for your own classes) and, of course, debugger features. It’s in the RC2 but final release is coming on a week or two.

Netbeans is using XDebug, for debugging. All you have to do is add xdebug extension to your php.ini and set some xdebug property like debug port, debug host and alike. There is a good tutorial here on the Netbeans wiki page. You can also use that link for a good debug tutorial.

Debugging is quite powerful and easy with Netbeans now. Even there are some missing things. You have to setup a debug profile from properties to be able to debug a url, that’s annoying. But it’s on the improvement list as I had learned. Also sometimes breakpoints does not work, even though that I’m sure that that part of the code is used but not opened as in active editor pane. But it does open closed documents if you use step by step debugging. There is also a javascript debugger, which is installed as a Firefox plugin. But I did not yet tried that.

Above from debugging feature of Netbeans Xdebug is also great at showing you errors. As a virgin of XDebug I really felt good when I saw the call stack for the current error. Xdebug replaces current error handler of PHP and shows call stack with error.

I guess it will be great. It’s really lightweight too if you just install PHP and not the rest, it’s only 24 MB. And code completion is also very useful and successful. The only IDE with support of custom class code completion was PDT and of course Zend Studio 6.x (also the lower versions were also supporting that.) which both are basically built on the same code base.

I guess from now on PHP Editor wars will be really great! As PHP grows and becomes more powerful, tools you use to develop it becomes far more powerful. It’s sad to see that C# had a built in debugger in Visual Studio for years even though it was younger than PHP. But I guess you need to have money to develop these kind of tools. At least we have a one now! And not just a black screen debugger and profiler but a GUI with powerful features.

By the way, Fedora is coming too..

PHP Namespace Issue

First of all, I’m not against it. I do not understand why it does really matter what the namespace separator is.

What kind of difference will it create to use “/”, “”, “:::”, “;;;”, “{{}}” or whatever. Well of course that I do not like to use a namespace like “thisisnamespaceseperator”. It must be easy to use, and when you look at it, you should see that some things are separated. Why there are so much discussion about it that I do not understand.

Any of them is ok for me. I can use “:::” or “”, what’s the real matter about it, I do not honestly understand. I do not think there is huge difference with My:::Class:::Bar() and MyClassBar().

Perhaps that because I’m a rookie, I also do not understand why someone will think to use a new language just because of one decision. I respect everyone’s idea and if it does not look good to you, then you should be using something else. I hate Python’s code look. A programmig language without { and } does not look good to me. But I think that if I go over my prejudice, I will like it.

I love to write PHP. I even love how it’s written php, with two lines down and one lineup. I love the freedom of being able to write both OOP and functional application, I love the syntax of PHP, I enjoy helping people about PHP, I enjoy joining to seminars, conferences and community activities. That’s the real power of the PHP. Ruby has also a community but they are arrogant, they are doing with the ruby way and they feel special. Just like using Mac instead of a PC. You don’t like how the “” looks like, don’t worry you will get used to it.

I don’t want to say that this namespace seperator is the php way of doing things. Because there isn’t actually such a way. Eveything is possible and can be done with PHP (even not much approved). I do not truly know how the php’s source code is written, so if the separator causes a lot of trouble, maybe “” is not the best of choice, maybe people are right that this won’t be an issue for the current release but you are ruining the maintainability of the code with these. Maybe they are right. But that’s a balance issue more than anything. If you have so much performance problem, that write your code on assembly and you will get the best performace you can have.

I hope that this issue will be forgotten with the new release, but I don’t think so. Some people may even fork PHP and create a new language myPHP. I hope that won’t be the case. The decision is made, and your whining may not change this. What we should do, is to respect the decision and keep trying to improve PHP and if we really really want to change this, try to influence the decision for PHP 6 with facts. Do not talk about speculations but actual facts. I used this and that happened, if we had used this this would be better and else. But I think this can’t happen till new release.

How to Customize Magento Product Page

I’m back with another tutorial about Magento. I’m not the best man you can find about Magento. But I’m trying to learn something from forums. The best you learn something is when you can explain it to someone else. So this is for that!

As I had mentioned in my previous post Magento is an open source ecommerce application made with PHP and Zend Framework. Company behind it is very dedicated to this project and works a lot about it. But the missing part is the tutorials I guess. There isn’t enough entry in their wiki and if you want to learn something, you have find it out yourself. So let’s begin!

This tutorial will cover basics about how you can find your way in the magento code and get to the right place and how you can change a product’s page design by changing the place of the images from left to right.

I tried this on Magento version 1.1.3 and it worked. Check here for the latest version.

First of all we have to understand which part of the code does show the product’s detail page. You can guess of course. But don’t do it and open the Magento folder. Navigate to /app/code/core/Mage/. Then you will see.

No I mean it, really! Go and look on that folder! So your best bet will be the Catalog folder. So is mine. So I enter the folder and look for things which can suit me. Well As I’m a bit familiar with Magento and I know that they have mostly separated the logic and design. So there must be somewhere where this binding must have been done. So the people who has read the previous post and people who are familiar with Unix systems, they must have noticed the etc/. Yes this is the folder you are looking for. In it, there is the configuration file: config.xml. Not that hard to find I guess. Now the real problem is to find out, what is related with what?

config.xml is a huge file and if you don’t know what you are looking for you are in a bit of troube but don’t be afraid. Let’s cover the details a bit and make an understanding. In my previous post I had entered some information about modules’ configuration files. But it was a small file and let’s say I knew what I had to write. So let’s look under the hood. For people who does not want to see how the engine works, the file you are looking for is /app/design/frontend/default/default/layout/catalog.xml. (Maybe instead of looking to code I should have checked folders better :)

There is a version info, ok. There is an admin part, which does not mean a lot to you nor to me. Maybe it’s something fatal but it doesn’t mean a lot for us (Nothing more than a newbie I’m). So the next part I’m more comfortable, as I understand what it belongs to. Well first of all, we know that this part is global. It will be used for all the parts where this module is being used. And the next part is models. This is about database fields. You can see that, below the models, there is the definition of a resourceModel to a class. This means the class defined in this config, will use that resourceModel. But what is this model? Next part is this. You see that the name of the resourceModel (catalog_resource_eav_mysql4 for me) starts now and a lot things is defined. Classes (let’s say the database’s driver folder) and database tables related to this resourceModel are listed here. It basically says that, this attribute comes from this table. You can be shocked by the count but open your phpmyadmin and you will see that there are 192 tables in it. Ouch! The only important part is that (if you don’t want to change the core aspects of course), if you are stuck which table is what, you can always look to these configuration files and find out which table is related to which module. A bit confusing but better than nothing.

Forget about the database and let’s keep going on the config file. Passing to models we come to the resources part. I guess this is about what connections will be used for querying and other things. You see that in catalog_read, there is a connection value and this is core_read. You may guess that it defines which connection this database drivers will use, comes from here. You are right, probably. But I’m not sure, and it doesn’t look I need this part to change the place of the picture, so I move on.

And now comes the block part. This isn’t new and I’m happy to see something that I know from my previous experience. In CMS pages, this part of the configuration had helped me to get to the layout so this might be the part where the output is given. So I get to the /app/code/core/Mage/Catalog/Block/ there are some parts about products but this is the backend part as I see. There isn’t any meaningful htmls in files which are in that folder. So I had a hope that I had found it, but it seems that this is not the case yet. So I move on.

Now a part that I do not even have slightest idea comes and I pass. The next part is adminhtml. I mean HTML! This can be it! There are some definitions about some things but I do not get it. There is a folder /app/design/adminhtml/default/default/ in the file system. And these bindings refer to the template folder. I assume there are some language additions and some other tweaks about admin pages. But again, I’m not sure.

Finally I have reached the frontend part. I’m now sure that this is the part I’m looking, as there are language definitions, per_page_values and layout! There are some things which still I do not get what are they for, but I see the catalog.xml. And this my best bet! I open the file and I see: Default layout, loads most of the pages! Yes I found it!

Below that part, there are things which are not much useful to me, things like url rewrites and some more configuration values. You can alter the general layout of Magento by changing these options by the way (As this module is about catalogs, the general view of catalogs of course, not the payment part!).

catalog.xml is a file familiar to me. From my previous post I knew there was something about blocks defining somewhere and this is it! There are blocks here and I follow the comments and finds Product View.

<block type=”catalog/product_view” name=”product.info” template=”catalog/product/view.phtml”>

This was the part I was looking for all the time. You see the template part?. It refers to /app/design/frontend/default/default/template/catalog/product/view.phtml. So I go there open the file and yes htmls!!! product-img-box line is very meaningful what I’m looking for and it has a css class. I make a file search between files and I find /skin/frontend/default/default/css/boxes.css. The product-img-box is defined in it and I change the float:left; to float:right;.

I open my web browser, open a product page and see that images are at right and not at left. You may have been more lucky if you just looked with firebug and saw the css and changed to it. But you wouldn’t had gained the insight you would have gained with this.

I hope that this was helpful. I’m not an expert on Magento. This article on Magento wiki helped me to figure out something. My previous post’s references were also valid. Do not forget to keep watching Magento Wiki and Magento Forums for best resources about Magento.

Using Custom PHP Codes on Magento

Magento is one of the newest and awarded ecommerce application right now. And I seem to have a project launched nowadays about it.

Above the ecommerce part like adding/modifying products, it also has a built-in CMS. It looks quite useful. Not very powerful though.  It just evaluates html code and not php. In most of the time this is prefered by the way. Because of security risks and things like that. But there are also cases which you want to do if you are importing something to magento or if you are just wanting to do in a quick and dirty way!

Well, the workarounds you find are not quite good. Simply they just take the CMS code, write it to a temporary file and include it, or writing a bit complicated parser inspired from joomla/mambo. Check out here for the details of the workaround. The tutorial I’m putting here is from there to, however I will also try to write solutions to problems that I have encountered (mostly because of magento versions).

This tutorial is working for magento version 1.1.8. You can download the latest version from here.

Now open up your favorite php/xml/html editor. While it will open up, also open your magento installation folder. Magento has a lots of folders for lots of things, which I do not know why. The code part is in app/ directory as you may guess. In the app folder you will find the etc/ where there are configurations for magento generally. Our PHP Code will be a module to the Magento, so we have to go modules directory and create a new xml file, named according to your module. The syntax is like: Parkyeri_customPHP. The first part till underscore means the name of the module, int this case Parkyeri. The second part indicates the component of the module. So you may have different components in one module, in this case customPHP, If we are talking about custom codded PHP pages, so in this module named Parkyeri, there can be different pages like: About, Contact, Jobs. And these are all different components, doing different things. If we were trying to create the About page then we had to use something like Parkyeri_About. You can add all of them in the same xml file.

Open up /app/etc/modules/ and create a file named Parkyeri.xml (the name of the module) and add these lines to file:


But what this means? You declare a new module named Parkyeri to the global site by naming the file Parkyeri.xml. Then you define in the module config file that, this module has a component named customPHP. You say that this component is active and the system can find it in the app/code/local directory by looking at the codepool

As you get it now we pass to the next stage. Now open up app/code/local/Parkyeri/customPHP/etc/ and create a file named config.xml (the default configuration file name for every module.) and add these lines in it.


What does it mean? This is more of a mapping file than a configuration file. What you are doing here is to map (you may also think bind) a class named Parkyeri_customPHP_Block to a block called parkyeri_customphp. So whenever a block of type parkyeri_customphp will be called, this block will look out for the class you defined in this configuration/mapping/binding file. But also you are defining the location of the component files that you want to call. In most of the cases, you want to call a component’s block from a module. So when calling you will say that I want a component named customPHP, and a block named test and this component is under the module Parkyeri. We move on…

Now the fun part, open up app/code/local/Parkyeri/customPHP/Block and create a file named Test.php and add these lines in it:

class Parkyeri_customPHP_Block_Test extends Mage_Core_Block_Abstract
    protected function _toHtml()
        //put here your custom PHP code with output in $html;
        //use arguments like $this->getMyParam1() , $this->getAnotherParam()
        $html = "Hello" . $this->getWorld();
        return $html;

So, we have finally reached the part which you are most comfortable, writing code! You will write down all the code you want to evaluate in this file. The _toHtml() method is called when you call it in the cms part. A magical function just like toString(). As you may remark the name of the class, is conventional according to the location of the class. That was how the previous configuration knew where to look when mapping.

And the final part is to embed it in the CMS, this is easy part. But the part where you get dissapointed most. Add this to page you want to show your custom php code:

{{block type="parkyeri_customphp/test" world="World"}}

So, it’s obvious isn’t it? In this code part, you say that, you want to put a block here. The type of this block is parkyeri_customphp/test. So actually you want a block named test under the customphp component which also a part of parkyeri module.  But you may be curious of the rest, on what I mean by saying, world. I’m sending a parameter to the class. Remember the code where there was $this->getWorld(). This world is that world!. So the code will print out “Hello World” (without an exclamation).
So this was it! Did it worked? No I didn’t did it? The real reason that it did not worked, is because, you did not refresh the caching system!! Yes, it’s that simple! It gave me a lots of headache though, hope it won’t to you. You can disable the caching from System -> Cache Management by the way.  Better then refreshing every time :)
If you are stuck on somewhere you should really check out magento forums. There are really helpful people out there from real developers, ceos and community experts.

Update: I have tested this code sample with 1.1.8 and all works fine.