Easy way to pass value by using Magic Methods in appRain?

12 Oct

In appRain we can avoid some unnecessary hassle to pass value using Magic Methods.

What is magic methods?
A magic method does not have a physical existence in Project code. We use this to pass value from one scope to another scope. Each magic method has a pair of two methods.
1) First method set value that always start with a keyword “set”. For example :


2) Second method retrieve value and it start with a keyword “get”. For example:


This method return value set by $this->setFirstName() and if value is not set then it return null value.

The “set” method always return reference it’s self class so that we can create a chain of call like bellow


What is the Problem of argument passing technique?
It’s really boring to pass lots of value in different scope by function parameters be cause it fixed developers in a frame. In some cases if parameters become optional then it’s taught to manage the sequence.
For example:

          "param 1" ,
           "param 2" ,
           "param n")

Let say in above example we like to skip param-1 but pass param-1 so you have to pass a default value in param-1 to maintain the sequence.

So, How does magic method help?
It’s really an amazing utility that we get form magic methods. Let say we have a function that we us to format product information, we can use magic method to set values like:


So we have create a chain of five magic methods to pass value and finally called formatData() method and in we will retrieve value like $this->getPrice() or $this->getUserId(). Now if we don’t like pass Invoice id simply you can comment it out or next time if we need to pass another value then simply we will add that another magic methods. And for the new change we don’t need to re-write function definition.

Show some Examples:
There are some good example when we save data in model like bellow:

See we can add/remove filed easily if needed. Let’s say we have create a plugin for authorize.net payment process were we have to pass bunch of parameters. We can do that simple like bellow.

$payment = App::Helper('Authorizedotnet');

// Batch - 1
// Batch - 2

// Batch - 3		

In this example we have set data in different steps and inside class we can catch it like bellow:

$post_values = array(
        "x_login"                    => $this->getXLogin(),
        "x_tran_key"               => $this->getXTranKey(),
        "x_version"	                => $this->getXVersion(),
        "x_test_request"          => $this->getXTestRequest(),
        "x_delim_data"            => $this->getXDelimData(),
        "x_delim_char"            => $this->getXDelimChar(),
        "x_relay_response"      => $this->getXRelayResponse(),
        "x_type"                     => $this->getXType(),
        "x_method"                 => $this->getXMethod(),
        "x_card_num"              => $this->getXCardNum(),
        "x_exp_date"               => $this->getXExpDate(),
        "x_amount"	                 => $this->getXAmount(),
        "x_description"             => $this->getXDescription(),
        "x_first_name"             => $this->getXFirstName(),
        "x_last_name"              => $this->getXLastName(),
        "x_address"                 => $this->getXAddress(),
        "x_state"                     => $this->getXState(),
        "x_zip"                        => $this->getXZip());

So, It’s pretty helpful to pass data or push it for a certain period.


How to Install appRain(CMF)

8 Oct

Here is a video explained how to install appRain Content Management Framework.

Finally! appRain is released with it’s extensive features

5 Oct

Finally! appRain is released with it’s extensive features. It has discovered few new things in web development and officially it is called Content Management Framework with two basic parts Content Management System (CMS) and Framework.

Generally, we face this problem when one of our potential client  starts a new project. Which tool should we choose? CMS or Framework!!

If we choose a CMS then we can give a quick output, but there is a chance to be stuck if the client wants to move the site to a big portal later with new features where those are not supported by that CMS.  Well! Lets forget CMS and start with a Framework, then we have to develop the site from very basic but we don’t have much time to spend because budget is low.

So! What is the solution?
Why don’t we get a tool with both of these two supports. appRain is developed to solve this kind of problem. It has two parts, one is Content Management System that has  lots of visual/interface level development tools and part two is Rapid development Framework that contains lot of core programming tools to support your project development at any edge.

Official website : www.apprain.com
Downlaod : www.apprain.com/download
Demo Website   :  www.apprain.com/demo
Here is some common features that we have in appRain

CMS Part Features

1. Custom Site Settings
Custom Site Settings are XML definitions  that creates interface in admin panel to process admin settings. Settings can be created in different tab or in a single page as per client need.

2. Interface Builder
It’s a XML definition to construct your admin panel. This definition file can be split Tab by Tab or in a single file. It helps to arrange(show/hide by ACL) admin tab and render page under admin panel in a user friendly way.
3. Page Manger
This tool helps to manage static pages that we need in the site. It has a very good contribution to manage page’s Meta Information. Simply create a static page as website section and give it to end user so that he can edit all meta information himself. 

4. Information Set
Information Sets are XML definition that creates a web interface in admin to process data and save in database. We can select various input types(event Calendar, Color Picker, Rich Text Editor, Category Set)  as a field. Each Information Set represents a virtual database table were we can execute SQL statement to access/modify data. Validation can be added in both Clients and Sever side. Call back function will helps for more extensive work.

5. Category Set
Category Set helps to process data in multi/single level category. It create Interface automatically for administrator to input data and save in database.

6. Member Management
It helps to manage members in all phase. A member can be an ordinary user just registration and login in site fronted that we call “appUser”. We have another type of user call ‘Profile User’ who can login as administrator and can process data. appRain tracks all of his data. With this feature multi-user website can be managed easily like wordpress, where each member  has an admin panel and website.

7. Email templates
This is a module to process email subject and body from admin panel and replace particular data with variables. Simply it makes a developer’s life easy to handle all emailing stuffs.

8. Admin Management
Super admin can create sub-administrator with proper access in different sections. Once a  admin updates the data system can track who/when data is updated. 

9. ACL
It’s an Access Control limit that we can define in Interface Builder definition to specify the privilege of Admin and profile user access.

10. pre-configured Blog
A pre-configure blog is available with the Demo site. So user can simply install and use that. 

11. pre-configured Store
A store is configured with Shopping cart and one page checkout system in demo site. Paypal and Credit Card (Authorize.net) payment process are implemented there. User can manage category and product update section and also Payment and Store setting in admin panel. There is an order manager section for administrator.

12. pre-configured Dynamic Gallery
In gallery, section 5 photo galleries( FlashGalleryASymbio, UvumiGallery, AinoGalleria, SmoothGallery, ElectricprismSlideShow)  are installed as example with lots of configuration. User can select any one gallery from admin section to be rendered and can change the Transition effect from admin settings.

13. pre-configured Forum
There is a Simple Forum installed in demo site to manage community input. User can manage category, Thread, Post, comments etc from admin panel.

14. Installer.
A built -in install is available to install the project in server and do the dependency check. appRain require at least PHP5 and mode_rewrite access to run in full phase.

15. Very Well Defined Cache Management
More caching more faster. Admin can manage different types of cache. User can clear/enable/disabled from admin panel. Also a developer can create cache for a particular Data Block or HTML for quick reference.

16. File Manager
There is a Multi file uploader available in admin Tool Bar so one can update file in system using those.

17. Rich Text Editor
Rich text editor can be configurable with Textarea as per need. Now appRain is using CKE editor but there is a plan to install more light text editor. This rich text editor can be enabled/disabled from admin setting.

18. Accordion:
Sometime user feels bored to see lots of setting options in one window then admin can enable accordingly to make those collapsible.

19. Database Backup tool
There is a tool to Backup/Export/Roll Back data base in admin panel 

20. Deleted data recovery
If any entry is  deleted then appRain creates a cache from 7days (Default time) to recover if needed. Data saved in a serialize format.

21. File Editor
There is a file manager to edit code from admin panel if needed. It’s an handy tool for quick support.

22. Language Module
appRain has a default language module to manage multilingual support. Administrator can manage language data from admin panel

23. Theme Manager
appRain can separate it’s design in separate theme.  Basically it’s an addition layer added in View section of MVC pattern. It’s helpful to change layout or multi domain site.

24. Multi-Store Management System
appRain can be configured in multiple domain with one installation. We can configure theme, starting point etc for each site.


1. MVC
It’s a popular pattern that most of the framework uses.  It separates the development in three different layers which are Model, View, Controller. But in appRain there is another one sub-layer added called “theme” inside View.

2. Model validation
Different type of validation rule can be added in model and this rule are checked when we try to save data in a table through model and raise exception if needed.

3. Model Installer
In apprain each model has a version that is saved in database. If we like to run a set of SQL statement automatically by system then we can create an installer and update the version from code and system execute the SQL one time and adjust model version. This method is really helpful when lots of developers work together and reduce pressure of Database administrator. And if SVN is used in project development then new SQL update are easily shared by Developer.

4. Factory Pattern
appRain manages all it’s Object through factory pattern to optimize resource. Factory add Single Tone pattern as per need to reduce the over initialization of object allocation.

5. Single Tone Pattern
appRain load most of the resource in Single Tone Pattern. So there will be no over initialization of one class instance.

6. EAV
appRain creates dynamic Data-process interface by InformationSet and each interface is initialize to database. All data save following EAV module where we dont need to create lots of database table physically but access data like a Relational data base Table. .

7. Search Module
Search module helps to create a result from over all project data by calling few simple functions. It reduce the hassle of writing lots of Queries by developer. 

8. Caching (11 types)
Several type of file caching is used to make the site faster and all these caching configurable. Developer can do manual cache by “Cache” module to quick data cache of a complex calculation to reduce system press.

9. URI Manager(Router)
It’s a fantastic tool to manage Website URL. We can re-write URL, Fix the project starting and even fix the total project in a particular point. Developer can pass hidden variable by URL which helps to use one Controller Action Method in different purpose.

10. Helper
appRain has lots of predefined helper. Developer can create new helper or overwrite core helper as per need.

11. Plug-in
Plug-in is a process to attach 3rd party class with appRain environment. Class can be either auto load or register.

12. Add-on (Attach 3rd Party Script based extensions)
Add-on helps to add JavaScript, CSS, Flash type resources. Each add-on has a XML definition to load it and we can configure it in different ways from definition XML or Controller Method.

13. Module (appRain Library)
All core library is called “Module”.  Generally module are abstract class to restrict resource share.

14. Magic Method in all module
appRain process some magic methods that really help to transfer data in different scope.  If you see a method like $this->setFirstName(‘Jhon’) then you may not get this method any where in coding but don’t worry it’s a simple function to set data and we can retrieve  value like $this->getFristName().  Each “set” method return Self Object that helps to create a chain of function call. Like $this->setFirstName(‘Jon’)->setLastName(‘Regan’);

These also helpful to save data in a model when developer feel boring to construct Array Format. Then we can use Magic method like bellow:
         ->setTitle(‘Need your help’)
         ->setSubject(‘Client Inquery’)
         ->setMessage(‘How can I install appRain’)
15. Auto load class by Path
appRain maintain a conversion in class name so it can be auto loaded. The class name create with combination of it’s location. Say for a example, if a class exists in “development/plugins/mailing/phpmailer.php” then class name should be “Development_plugins_Mailing_PHPMailer” so it will be load automatically by auto load feature.

16. EDP
EDP mean Even Driven Programming that help to attach an even on runtime. The pattern is implemented in Data Grid Helper.

17. Data Grid
This helper helps to create a HTML data output in Tabular(Two column) or Grid format.

18. PDO (Database layer)
PDO is used as a database layer that helps to integrate different type of Database System. 

19. Web Service (Using PHP reflection API)
Help to crate API using Web Service by WSDL. PHP reflection api is used to create WSDL but user can add custom data type as per need. 

20. Cron Job Setup(Using PHP reflection API)
This helper helps to run scheduler process. And all Schedule time read using Reflection API so user simple add the Time Duration as function comments.

21. Cryptography
This module helps to create different types of data encoding. Its really helpful to respond in AJAX helpers as in JSON format and Password encryption using Salt.

22. Export Resource outside
It’s really an interesting  feature. We can export most of appRain resource out side of it if we like to use/import any resource in to other environment. For example, if we like to do a Unit Test using “Simple Test” tool but finally we don’t want to release the project having the Unit Test module integrated with it. In this case, we can simply export appRain objects and pass it in unit test module and do necessary test out side of it.

23. Configure Multi-theme and Multi-User Site
There is a feature called Profile User mode that helps to crate profile base multiple site. Where each user will get an admin panel and a website.

24. Configure Multi-Domain site
We can configure multiple domain in a single installation of appRain. In this case administrator can access multiple sites from one admin panel.

25. Deleted Data Recovery
appRain can Log any deleted data for a certain period of time in  as serialize format. So that, it can be recovered as per need.

26. Core Configuration
appRain save all System variables in a XML definition file and there is a particular Helper to load those configuration if need in rare case.

These are some common features that are available in appRain.

CSS tricks to create star rating in an easy way

23 Apr

Let see some CSS tricks.
Some time we feel sick to display start rating. But we can do it very easily with CSS tricks. What we need a image with all combination of starts. See following one that I have used for my example:

We can adjust all this rating with CSS see the following classes

.rating-parts {
	background: url(star-matrix.gif) no-repeat 0 0;
	height: 16px;
	width: 80px;

.rate1 { background-position: 0px -16px; }
.rate2 { background-position: 0px -32px; }
.rate3 { background-position: 0px -48px; }
.rate4 { background-position: 0px -64px; }
.rate5 { background-position: 0px -80px; }

Now see the HTML for rating 3

<div class="rating-parts rate4"></div>

Here we are adjusting all image position with CSS for a particular element. See the following combination of class for rating

rate 0: rating-parts
rate 1: rating-parts rate1
rate 2: rating-parts rate2
rate 3: rating-parts rate3
rate 4: rating-parts rate4
rate 5: rating-parts rate5


Shell scripting in php to balance your load

19 Apr

It was an issue while I was working with an API module in Magento. I really like the environment and the PHP ticks they used in their development especially I become a great fan of Factory Pattern now.

I had an API call to complete the checkout from a remote server using Magento API and the checkout process executes another 10 to 12 API calls in another server to complete the total process.So see the scenario here.

API CALL Diagram

But, above system will not complete anymore because it will take time more than PHP Maximum execution time.

Then, I have decided to open a new process in Linux with shell script and assign the next API calls there. Checkout API function return after triggering that new process for the further task. The new process execute on its ways and do necessary update in database and then die by itself.

We can do that with a simple Shell call from PHP. Like:

 bash shellscript.sh  Arg1 Arg2

It’s a simple command to run a shell script from command line with command line arguments. But main problem I faced is… to make PHP Asynchronous.
We’ve lots of functions to execute command line instruction like bellow:
exec(), shell_exec(), system(), “

None of these functions will server this problem. All these functions wait until capture any response. But we have to open a new process and have to return leaving on its way.

So I have used the following example. Here we have opened a new process and close it as well:

Proc_Close(Proc_Open ("bash c2m.sh 4 1_2_3_4_5 &", Array (), $foo));

I have added an ampersand(&) that means I don’t care it’s return value.

Rest of the task is pretty simple. In Shell script we capture the command like argument with $0, $1, $2 … etc and we can execute an PHP script in command like bellow


`php myscript.php $1` 

This command run myscript.php and send a command line arguments. All command line argument saved in a PHP variable called $argv

Always use a back quote(`) to execute a php file in shell script if you want to store the output in a variable.
See the following example:


result=`php myscript.php $item_id`

echo "$result"

This is how you can pass your load in Linux to execute command line to get relief from time expire issue. 🙂

Download Example source code from here

PHP Webservice Class

4 Mar

There are lots of extension available to create PHP Web service Like Nusoap or WSDL helper. But it’s not too taught to create a web service if you understand WSDL definition, PHP reflection API and have a bit knowledge of to create and parse XML Document.

Here I have shared a PHP Web service class with some example of Client/Server implementation. That I developed to crate a plug-in for me.


– Parse a PHP Class and create WSDL definition
– Use SOAP for Client Server Communication
– Easy to integrate and develop in a very simple way.
– A Cryptography Class is integrated to handle JSON format data.


– PHP 5 or greater Version
– PHP DOM(DOMDocument) extension


– This class generate WSDL document for all common Data Types(String, Integer, Boolean, Float, Double). Complex data type (Class Objects) are in further development.


– Use JSON ( Cryptography Class added here) to pass complex data type like Array


Version 0.1.0
Download Link
SVN http://php-webservice-class.googlecode.com/svn/trunk/

PHP Class to Export/Import MySQL database

4 Dec

Last night I was getting fed up on updating my remote database from my local. It’s a pain to login hosting control panel each time then import data.

Then I thought, why not I develop a small script for that. Finally I came up with a PHP class to import/export MYSQL Database. Let me share with you.


– PHP 5 and DOM XML.
– Truncate all previous data.
– Do not Drop/Alter database table
– Database Schema and Data save in XML format.


Version 0.1.1 (New):
Download Link
svn checkout http://backupdatabase.googlecode.com/svn/trunk/

Version 0.1.0:
Download the script from box.net.


/* Include the lib file */

/* Dabase configuration */
$db_config = Array
                'dbtype'    => "MYSQL",
                'host'      => "DB_HOST_NAME",
                'database'  => "DB_NAME",
                'user'      => "DB_USER",
                'password'  => "DB_PASSWORD",

// Initiate  main class
$dbimexport = new dbimexport();

/* Download the file from browser */

/* Save Database file in disc */

/* Import database */