Categories
PHP

Zend Framework: Debugging and Loading Custom Ini

Another blog post for self documentation 😉

Debugging:
Create a init() method in the controller. Put the following codes to disable the layout and turn off view rendering. Now, use print_r(), var_dump() or try…catch whatever you like 🙂

Please note: please make sure if you have any layout enabled already, if you don’t have one, trying to disable the layout will obviously go wrong. In that case, uncomment the respective line.

Even without all these hassles, anywhere in your controller you can use Zend_Debug::dump() which works like var_dump(). But it won’t work in case there is an Application Error (a fatal error somewhere). So, try…catch is a better debugging solution when you can’t trace the source of the problem. For a quick debugging, use Zend_Debug::dump().

Loading Custom Ini

Create a ini file in the “application/configs/” directory. Lets name it mydata.ini. Then create a block of data like this:

Now, you can load these configuration anywhere using the following codes:

The second parameter of the Zend_Config_Ini constructor loads a specific block from the ini file.

Categories
Linux

VirtualBox, Windows and Linux: Getting the best out of both worlds!

Windows and Linux are two entirely different OS. They have their own strengths and weaknesses. Many software and solutions are unique to either of the platform. If you’re an intelligent person, you’d love to get the best out of the both platforms.

If I talk about myself, I need Windows for many reasons. For academic purposes and as because of some minor but critical compatibility issues. My Notebook PC has issues with WiFi connectivity on Linux. Same goes for my Nokia X2 which can not talk to my PC via bluetooth if I am on Linux. On the other hand, I am a LAMP engineer. Linux is a must for my day to day works. In the past I used to run a Windows XP inside virtualbox. That used to solve some of my problems but not all. To be honest, till today, Windows has the best hardware compatibility no matter how their other features suck. We can argue whether it’s the fault of the hardware manufacturers or not but that won’t change the fact at all.

Finally, I have decided that I shall keep Windows 7 as my default OS and install Ubuntu inside virtualbox. In this way, I can access the required features of the Linux platform (LAMP, Postfix, nGinx and all others) and at the same time enjoy the benefits of Windows.

Even more interesting, I can share directories between the OS, so I can easily share my www on Windows and make the same stuff available on Linux. I planned to make the shared www the doc root of the apache in Linux so I can test the same application on Linux without hassles. This will give me the ability to try those PECL extensions, PEAR packages and other contents which are generally not available for Windows. So what did I do?

1) I installed VirtualBox (http://virtualbox.org)

2) I inserted my Ubuntu 10.10 disc. I proceeded with creating a virtual machine. On the way, I created a virtual hard disk in VirtualBox for the installation. The wizard is pretty simple. Anyone would be able to install Ubuntu on VirtualBox with ease.

3) After the Ubuntu installation was complete, I logged into the system. From the VirtualBox Window, I went to “Devices” menu, then clicked “Install Guest Additions”. This command added a CD to the virtual machine (Ubuntu). I went to “Places” > < Virtualbox Guest Addition CD name >. I double clicked the “autorun.sh” file and ran it on terminal. After a few moments, it was installed. The Guest Additions enable file sharing between the guest and host OS.

4) In the VirtualBox window, I clicked on “Devices” menu and then “Shared Folders”. I added a shared folder named “www” with full access. This was in fact the www root of my WAMP server.

5) Then I logged into Ubuntu and installed LAMP. After that, I opened up the “/etc/rc.local” file and typed in the following command:

What did it do? It actually mounted the shared www in /var/www when the machine (Ubuntu) started up. Making my WAMP server www available on LAMP. Since I have given the folder full access while sharing, I can use the terminal to do some dark magic on the files as well 😉

So, from now on, I no longer need to struggle while creating a “.htaccess” file or “index.php” file on Windows. Terminal will do that. 🙂

If you want to access the LAMP localhost from your Windows, go to “Devices” > “Network Adapters”. Add a “Host only adapter” to access it from the host OS. If you have a router and want to forward your port to the virtual machine, add a “Bridged Adapter” and select your WiFi or LAN driver.

After setting up the adapters, restart your machine and open terminal. Type in:

You can see the IP addresses attached to the virtual machine. Apparently you can access the LAMP www both via eth0 and eth1 IP address.

I have an exam tomorrow but couldn’t resist to share the little experiment and the awesome outcome! I was on a haste and everything might not be clear. Feel free to ask any questions. I shall respond when I can manage some time 🙂

Have fun!

Update: Backup the virtual HDD. In case something happens, you will be able to reuse it and skip all the installation hassles.

Categories
Work

Quick Hash – A tool to generate hashes on the fly

I very often need md5 hash in my day to day development works. I used to use php or python to generate the md5 hashes by writing a short script.

Today, while trying .NET, I built a GUI tool to generate md5 hash and base64 encoded strings on the fly. The app requires .NET framework 3.5 SP1. It’ll run fine on Windows 7 (and Windows Vista as well, I think) without any additional installations. On earlier systems, you may be required to install .NET framework. You can use it on Linux or Mac via Mono (though I haven’t tested it myself).

I have plans to extend the program and open the source. Will do sometime soon.

Download, Install and give me feedback! 🙂