Monday, 3 July 2017

What is ORM Framework?


ORM is for Object Relational Mapping, an ORM framework is written in an object oriented language (like PHP, Java, C# etc…) and it is designed to virtually wrap around a relational database.
Basically, the ORM framework/software generates objects  that virtually map  the tables in a database. Then you as a programmer, would use these objects to interact with the database. So the main idea, is the programmer should write optimized SQL code.

let's suppose you need to add new client in database, you would just have to use the ORM’s clients object to add the new client.
For example:

client = new clients_object("Stefan","Mischook");
client.save();

The above of course, is just pseudo code, because the syntax will vary from ORM framework and from language to language.

When to use an ORM framework?

I would start considering the use of ORM when:

  • You have 3 or more programmers on a web application. 
  • Your database consist of 10+ tables. 
  • You have say 10+ queries to make.



ORM Frameworks for PHP programmers

Here are a few ORM frameworks to consider:

  • Doctrine
  • Part of the cool Zend Framework Zend Db
  • CakePHP has ORM built into it.
  • RedBean ORM without configuration!

Saturday, 19 March 2016

Setting up a permanent 301 redirect via .htaccess on Linux server

Redirect individual files

To redirect individual files, like example.com/oldurl.htm to newurl.htm you can use a 301 redirect like this:
Redirect 301 /oldurl.htm /newurl.htm
To redirect one specific file to another domain such as example.com/oldurl.htm to example.in/newurl.htm:
Redirect 301 /oldurl.htm http://example.net/newurl.htm

Redirect an old domain to a new domain

If you had an old domain name such as xyz.com, and now you decided you actually want to use new domain xyz.in for the website. You could setup a 301 redirect for the entire domain, so that old links to xyz.com carry over.
Code in the xyz.com domain's .htaccess file:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^xyz.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.xyz.com [NC]
RewriteRule ^(.*)$ http://xyz.in/$1 [L,R=301,NC]

Force to use www. in domain

A search engine like Google,yahoo,bing would see xyz.com and www.xyz.com as essentially two separate websites. They recommend you pick one version
Code in the xyz.com domain's .htaccess file:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^xyz.com [NC]
RewriteRule ^(.*)$ http://www.xyz.com/$1 [L,R=301,NC]

Friday, 19 February 2016

Enable mod_rewrite in xampp

For some reason my install of XAMPP didn’t have mod_rewrite automatically enabled? Not really sure why  but basically below are the instructions on how to enable .htaccess mod_rewrite in xampp.

1. Go to the directory of installation C:\xampp\apache\conf
2. Open and edit httpd.conf in a text editor

3. Find the line which contains
#LoadModule rewrite_module modules/mod_rewrite.so
and change to
LoadModule rewrite_module modules/mod_rewrite.so
Find all occurrences of
 AllowOverride None 
 and change to
 AllowOverride All

Now restart the apache server.
You can see now “mod_rewrite” in the Loaded Module section while doing “phpinfo()”. 

Sunday, 7 February 2016

How to Disable Theme and Plugin Editors from WordPress Admin Panel

By default WordPress allows users to edit the theme and plugin codes through the admin panel. While it is a handy feature, it can be very dangerous as well. A simple typo can end up locking you out of your site unless ofcourse you have the FTP access. To prevent clients from screwing up the site, it is best to disable the theme and plugin editors from the WordPress admin panel. In this article, we will share with you a one line code that will disable theme and plugin editors functionality from WordPress.
All you have to do is open your wp-config.php file and paste the following code:
1define( 'DISALLOW_FILE_EDIT', true );
And you are done.
One of our users pointed out that if you paste this code in the theme’s functions.php file, it also works.
Refrence from

Wednesday, 3 February 2016

How to Remove Menu Item in WordPress Admin Panel

Have you ever worked with a client who has a hard time understanding technology? Well, as a consultant, designer, or developer, it is your job to make things easier for them. WordPress admin panel comes with a lot of options in the menu, but you can get rid of them fairly easily if necessary. With one of our clients, we needed to get rid of few menu items, so it is easier for her to understand things. In this article, we will show you how easy it is to remove a menu item in the WordPress Admin Panel.
For WordPress 3.1 or above, just paste the following code in your theme’s functions.php file:
1add_action( 'admin_menu''my_remove_menu_pages' );
2function my_remove_menu_pages() {
3    remove_menu_page('link-manager.php');  
4}
In version prior to WordPress 3.1, you would need to paste the following code in your theme’s functions.php file:
01function remove_menus () {
02global $menu;
03    $restricted array(__('Links'));
04    end ($menu);
05    while (prev($menu)){
06        $value explode(' ',$menu[key($menu)][0]);
07        if(in_array($value[0] != NULL?$value[0]:"" ,$restricted)){unset($menu[key($menu)]);}
08    }
09}
10add_action('admin_menu''remove_menus');
The code above will get rid of the Links option for all users (including administrators). Only two user roles are allowed to see the Link tab (Administrators and Editors). Now if this is for a multi-author site (where there are many editors), and you as an administrator still want access to the Links menu, then you can add parameters to do so.
You would need to utilize the function current_user_can(), and with a simple if statement, you can get rid of the link menu or other items for specific user role.
This is a very handy trick for consultants and developers who work on larger sites.
Refrence from