Review : Crystal Database Wrapper for PHP

Crystal Database Wrapper for PHP
One of the sites i keep an eye on is greepit.com to know about some of the latest and coolest tools in web development. I came across this new Database Library or wrapper called Crystal database wrapper. The library really looks promising and in fact appears to be minimalistic as they claim. They also have a data validation module and manipulation module which is all you need to create basic to intermediate apps. From the user guide i looked at some of the examples of CRUD and i just felt it’s Active Record from Codeigniter. As i did a lot of Codeigniter sites so far, it just looked so comfortable to me. Just for an example.

 

Zend Casts Video Download links

I’ve been writing an Ajaxified App in Zend with Doctrine and was looking for some efficient ways or shortcuts to get a good grasp on Zend+Doctrine. It seemed a bit difficult in the beginning to integrate Doctrine in Zend Framework. Then i came across this huge resourceful site zendcasts.com where a massive number of Zend Framework tutorial videos are there. Got 5 video tutorials related to Doctrine which are awesome. The best part is that there are corresponding project files hosted in google code for most of the screen casts. This is a huge help since you get ready made thing what you have just seen. Looking at the index there,  a treasure of zend videos popped up by this nice guy – Jon Lebensold. Then i watched lot of those but wanted an offline ways to watch at my discretion. So i had to hack the video sources using firebug and prepared this list  to download the videos so that other people may download these videos and watch them offline. Here’s the list :

http://www.zendcasts.com/wp-content/uploads/2008/12/zc1-technology-overview-screen.mov

http://www.zendcasts.com/wp-content/uploads/2008/12/zc2-setup-folders-for-zend-mvc-screen.mov

http://www.zendcasts.com/wp-content/uploads/2008/12/zc3-creating-a-zend-index-file-screen.mov

http://www.zendcasts.com/wp-content/uploads/2008/12/zc4-creating-controllers-screen.mov

http://www.zendcasts.com/wp-content/uploads/2009/01/zc5-adding-a-doctype-and-stylesheet-with-zend-screen.mov

http://www.zendcasts.com/wp-content/uploads/2008/12/zc6-using-blueprintcss-with-zend-screen.mov

http://www.zendcasts.com/wp-content/uploads/2008/12/zc7-custom-routes-with-zend-controllers-screen.mov

Interview for PHP programmer

So, in Blueliner Bangladesh, we needed some PHP programmers in the coming months. I almost took over 20  interviews from screened out CVs and found some good candidates. There’s some points we’d like the programmers of this country to be concerned about. Here are some of my observations and recommendations.

You have to learn yourself. Company may not give the opportunity!

This is one of the most common pitfalls i found in this recruitment drive. Most people complain that they don’t get enough time to learn about the latest tools and technologies. But the thing is, It’s your career! the companies will always try to get the best out of you within shortest possible budget and time. And at the same time you have to enrich yourself not only through the projects you get but also with some voluntary open source projects. What most companies don’t realize that, if the programmers are not given some room to do R&D, it’s eventually the organization who will lose by compromising with the standards of the programmer against budget. And the programmers are not updates with the latest tools technologies. So, guys! you have to take some personal effort to play with the newer things. Even if you don’t get a minute in the workplace, find some time at home to do some R&D. It will pay off inshAllah.

Ability to do things VS Ability to do things with Art.

There are hell lot of renowned Javascript programmers but how many do we know? John Resig, Jack Slocum, Remy Sharp and so on. Why do we know them ? Because they did something which others didn’t. They did things with Art for which we know them. So all the promising programmers, please concentrate on doing thing with Art. If you know jQuery, learn how it works, who’re the people behind it, follow them on twitter, read their blogs. Let alone John Resig’s Blog can give you a very good insight what’s being cooked for the next generation javascripts. BE detail oriented about things you play everyday with. You’ll always be appreciated for things you want to do not “things you had to do”.

Object Oriented Programming

PHP had been very lose in standards and conventions when it comes to Object Oriented Programming. The recent releases of PHP are much more matured that it used to be in the past. I started in 2000. We can do lot of things without even following the standard way. But dear PHP programmers, better companies or promising companies will take you because you’ll make some magical changes, add some new dimensions in the organization. So please be very clear and efficient about Object Oriented Concepts and way of doing those things in PHP. There’s a difference between a programmer who declares a class “abstract” knowing when it’s needed and a programmer who knows OOP but doesn’t want to declare the class abstract. PHP is not at the pick of it’s maturity. So try to discover which things are absent in OO PHP which are there in other languages (C++,Java, Ruby).

Have some publishing activities

To present yourself as a passionate programmer, you gotta have a blog or some sort of publishing which is visible on the WWW. If you have a blog and you write about things you play with, problems, time saving solutions, it will help you a lot getting the attention as a good, focused and passionate programmers. So start your blog now if you don’t have one. It takes a little time to get used to with some writing habit.

Care more on the CV

May people simply flooded of with bunch of tools and technologies. Many of cv looked like they are Jack of All trades. But hardly anyone was proficient in all they mentioned. So please, do not put items on which you don’t have substantial hold of and just for the sake of filling up CV. If you write you are good at Javascript, expect advanced level questions from JS. If you write “Good in OOP” , expect higher level questions from OOP.  Make the CV withing 3 pages maximum. It irritates the interviewer when people have long descriptions about each project you have worked on.

There are other points i wanted to write but the post will become longer than the comfortable or acceptable length. So i’ll share some more next hopefully.

Sorting table columns in mysql by adminer

Sorting columns in a mysql table has always been a nasty way to deal with. It can be done some sql commands of course but this is not what we do more often. Even the most popular DB admin package – phpmyadmin doesn’t provide such utility to sort or re-arrange fields in mysql. It occurred to me a lot of times that i had to bring some filed to a different position for convenience after i first created it. But i had to run some queries which i never liked, to do this task.

So ADMINER (formerly phpminadmin) comes up with a nifty utility in their one file standalone package.

If you haven’t heard of Adminer yet (you must have missed a great tool), download from http://www.adminer.org/en/

And run it from your web server from any location. After entering credentials and selecting database, just select a table from the left which appears like this.

adminer_table_select

Now you get some options like – Alter table   |   Default values  |   Select table  |  New item

Select Alter Table and you get a screen like this

adminer

Alright, you pretty know what to do with those up and down arrows now. Don’t forget to save the changes :)

Killing session on browser close in Codeigniter

It may be well known to some people how to kill sessions on browser close but the default config in codeigniter doesn’t provide so. In lot of application which has admin interface, we don’t want browser to store the session. So it needs to kill the session when browser is closed. Example behavior can be found in yahoo email page.

So how do we do that in Codeigniter ? It’s simple, although this feature is not well commented or documented. Ok, now open system/application/config/config.php file

And find the settings called $config[‘sess_expiration’] under the section Session Variables and put the value like this

That’s it. Now your session will be killed in the event of browser closing.

Form Validation Callbacks in HMVC in Codeigniter

Many of us are using the HMVC extension (Hierarchical Model View Controller) in codeigniter which is available. http://codeigniter.com/wiki/Modular_Extensions_-_HMVC

HMVC helps developing modular apps in a very convenient way. All the things work simply fine just like a clean CI installation. There’re 1 or two exceptions which i have found. One is the callback of Form_validation class. If we are making some forms like registration we check emails and usernames and we do it in the form validation class using callbacks. If we look at the basic callback structure when validating forms from CI documentation, it appears like.

 

But this callback will not simply work. Some of my precious hours went why it was not working. Then i navigated the Form_validation.php in /system/libraries folder around line 580 which looks like

 

The function – method_exists returns false even if the callback function is there in the Controller and after all in the CI loader object. So it came out from the forum that you have to do a little extension to Form Validation class which is

 

And when running the validation like in earlier code

you have to provide an addition $this as a parameter to run method. which will look like

Now, your validation callbacks will work perfectly.

Another note, if you’re trying to access a public variable of a controller via the get_instance() in hooks , you’ll have to write in your controller like this.

CI::instance()->var_name = “Some Value”;

May be there are some other required adjustments when using HMVC, but i came across this two time killing adjustments.

Upload all your files in lowercase in Codeigniter

You might all probably know that *nix systems treat myPic.jpg and MYpic.jpg different while windows systems don’t . So there’s always been a need to deal with filenames across different systems. We upload files which may be in lower case, uppercase or a mixture of both. This sometimes kills our valuable time and effort. To deal with files uploading, edit and delete if we always assume that file names are in lowercase, it’s lot better unless we have significant reasons to keep the case of the files intact.  Codeigniter has a good uploading library which resides at /system/libraries/Upload.php. But unfortunately there’s no property of the uploading class that lets us to upload the file in lower case. So, the shortcut is to override the native method by your own library. When we initialize a library CI tries to find it within your application directory and then it’s System directory. So if we make a class MY_Upload extending CI_Upload, it can do the job. This is no trick, it’s documented on CI. So, now , we just need to override two functions in the CI_Upload class. These are _prep_filename and get_extension Here is how it looks




		


The code can be downloaded from here

my_upload

Unzip and put it in your /system/application/libraries directory.

Now for any upload you do using CI’s uploading class, will produce lowercased filenames.

Is Kohana moving faster than Codeigniter ?

Traffic Codeigniter VS KohanaPHP

Look at the Alexa graph above. What do u think ?  

I’ve been using Codeigniter in Mid and Fairly Big project for over a year and a half. Kohana was released before i started but the amount of online support and tutorials and an active company development (EllisLab) made me decide using CodeIgniter. But I keep checking updates on Kohana because it has lot of extra features over CI. It’s Strictly PHP5 OOP and has libraries like ORM which doesn’t exist CI’s distribution. Just out of curiosity, i went to Alexa and compared the traffic for CI and KohanaPHP and it really surprised me. Kohana is way ahead in terms of traffic. What does that mean? People are more involved with Kohana than CI ? Well, apparently YES. Kohana is community driven development. In CI, user contributes as addons to the Framework, which is ok. But when there’s an active driving force by the community, it’s better, at least i think. 

Moreover I read some articles how to easily use Zend in Kohana in the beyondcoding.com. So that makes me think of leaning towards Kohana for my next projects. There are of course ways to use CI with Zend though but the integration method of Kohana with Zend looked neat. It won’t get much tough to switch to Kohana because it was originally based on CI. And default design pattern in Kohana is Factory (as it appears) while CI is singleton. Of course I’ll need to analyze some more benchmarks for scalability and other features before shifting focus. 

PhpMinAdmin – nearest alternative to phpMyAdmin

I can’t possibly tell how many times i’ve been seriously irritated  navigating to phpmyadmin option of my hosting or hostings of the projects i have worked with. Most of the cases you’ll have to click many times. And in Plesk ? It simply sucks when it comes to use phpMyAdmin from there. I’ve always used phpminiadmin as a quick alternative solution because it needs no configuration and no install. But it’s very basic and needs too much typing to get things done. Today I found phpminadmin. It’s just the name without the i in php phpminiadmin. It simply rocks!! It has nearly every option that you’d normally expect from a db admin tool. And to me, it’s a substitute to phpmyadmin for ongoing operations.

phpminadmin screenshot

It has select, search, edit, index , create — almost everything u need. The best part is that it needs no install and it’s a single file weighing about 167KB.

But of course, i’m not saying it’s a fully alternative to phpmyadmin. No way. They have been developing this mighty tool for over nine years.  But phpminadmin surely is a very very good altenative of that for quick solutions. Check it out here.

http://phpminadmin.sourceforge.net/

Why didn’t I find it earlier ?  :-(

UPDATE : THE PROJECT HAS BEEN RENAMED TO “adminer” AND IS AVAILABLE at http://www.adminer.org/en/

Always use meaningful variable and function names in PHP

Think About the following code $a=”I Am John Doe”;

$b=explode(“ “,$a);

echo “Total Number of words in $a is “.count($b);

Now how about this, $name=”I Am John Doe”;

$num_of_words=explode(“ “,$a);

echo “Total Number of words in $name is “.count($num_of_words); Well, the example was too simple. But things can go terribly wrong when not using meaningful variable names in PHP or any other language’s codes. Even you’ll forget at some point of time what was the variable $a for and $b. And it really pisses other developers when using some one’s code which didn’t follow good naming convention. And when i see codes in those messy fashion it makes me angry like the Goku below.
Angry Goku

And the end result is inefficiency and waste of valuable time. There are various naming conventions practiced for coding. PHP has it’s own style where underscore is massively used. And it’s quite comfortable to use. $last_name is more readable than $lastname. So variables/functions can be made quite meaningful when they are written. To cut the story short, here’s some suggestions from me: 

Partners Section:

depfile password Depfile Premium Account Depfile Premium Depfile Premium Account Depfile Premium Depfile Premium Account Depfile Premium Account dep file Dep file dep file dep file dep file dep file Depfile Premium Account Depfile Premium yify torrent empire torrent yify vikings season 4 auto clicker autoclicker slender the eight pages he gift torrent walking dead torrent the walking dead torrent fl studio 12 torrent