Blogs of PHP

We are a web development and outsourcing agency based in Kochi, India.

Easy image manipulation with Imagick PHP Extension

When it comes to uploading photos, image cropping/resizing in a website, php GD library comes in handy. But if we need to add more complicated image processing functionalities to our website like merging multiple images, rotating or color processings like photoshop, php ImageMagick library helps to do such processes more simple with better quality output than php GD library. Availability The GD library is included by default since PHP 4.3 and available in most server environments. ImageMagick may not always be available and some of the hosting companies don't include it in their server. We can check the availability by using following code.

Beginners guide to customize layout in Magento2

It’s difficult for a beginner to go into Magento developer docs and understand the whole concept of layout handling with xml files. The layout files are .xml files located in the layouts folder of the theme/component. The layout file defines the position, template file, arguments, html attributes, etc. for each block. A template file (with .phtml extension) is the HTML part that is loaded by how the XML is configured. Magento has this feature to turn on template path hints which is an absolute lifesaver for beginners who try to figure out which template is used for a particular section. It also gives the block class name used. Below is an image of Magento showing the path hints.

Laravel – Custom authentication and what happens under the hood

Laravel – Custom authentication and what happens under the hood

In this article, we will take a detailed look at how the default authentication works inside Laravel core. But first, we will learn how to create a custom authentication. Laravel ships in with a great default user authentication. It even creates the views and routes for you if you run // Create the default views, routes and controller for authentication php artisan make:auth All is well as long as we are good with the default users table and its authentication. But what if we want another authentication method. For example, you want to user a separate table called admin for authenticating admin users while keeping the normal users table for front end authentication....

Laravel Facades Part 1 – What they are and how they work

Facades allow us to call classes defined under the service container in an elegant and expressive way - as "static" interfaces. If you are a Laravel developer, chances are that you are using Facades all the time. You may not just know that yet. Laravel ships in with many facades like Hash, Input, Mail etc. Let’s take the example of Hash facade and try to figure out how it works. You may be familiar with something like this, Hash::make(‘password’); If you search for a class named Hash, you won’t find it. Go to app/config.php and scroll down to the bottom where the class Aliases are defined. There you will see this,

CARBON – a PHP Based Date and Time Library

PHP developers often have to spend lots of time trying to manipulate and format time and date.  Especially in applications where date and time calculations are used extensively, like an Event calendar, or a scheduling system which works across different timezones. There are different php libraries available to this. In this article let’s talk about Carbon php based date and time library. Which we are quite impressed about with the use in a recent Laravel project. WHAT WE NEED The only thing that we need is Carbon library. Download it from github , unzip and copy that folder to your project library folder.  Or Use the following command to install with composer. $ composer req...

How to add custom post archive page links to WP Menus like page and post links

In WordPress menu section, it’s difficult for normal users to add links to the custom post archive page because, there are no options to add custom post archive page link like post, page and categories. If user wants to add an archive link, then the user must need to use custom link feature and it is very difficult. If there is an option like post or page links then it is very easy to manage links. So here describes how to add custom post archive page links to the WP menu section like post and page links.Please use the given code in your functions.php of the theme. Then check your WP menu page from dashboard. You can see an additional met box for listing all custom post links. Then you can just select the custom post and add it to the menus.Done !!. It is very easy!

Simple explanation of abstract classes and why we would use them

Lets consider an example. We are creating 2 classes for employees in an office. There are 2 kinds of employees, fulltime and contract employees. Both type of employees have some common methods and properties like, name, monthly salary etc.class EmployeeFulltime {   public $fistName  = '';   public $lastName  = '';   public $annualPay = 0;      public function __construct($employee)   {    $this->firstName = $employee['firstName'];    $this->lastName  = $employee['lastName'];    $this->annualPay = $employee['annualPay'];   }   public function getFullName()   {    return $this->firstName . " " . $this->lastName;   }   public function g...

Regular expressions in PHP

PHP has three sets of functions that allow you to work with regular expressions. Programmer s does not use these powerful functions often as it seems to be difficult to create patterns. Also it is not easy to find a basic and simple regular expression tutorial in a single webpage .  So I would like to give a try on this to collect the info and make it easy to learn and interesting. Also I will include some very useful reg-expressions in the end of this post. About regular expressions A regular expression is a pattern that can match various strings. Regular expressions started as a feature of Unix shell. They were made to make string operations easier. It’s really useful in programming with PHP as they help to reduce a lot of codes. As a simple example we can say t...

Estimating Shipping Rate on Product Details Page in Magento

To display the shipping rates on the product view page in Magento 2, you can use a custom block and template. Just follow these simple steps to make it happen: Create a Custom Module: If you don't have a custom module yet, it's a great idea to create one following the best practices for module creation in Magento 2. Create a Block Class: In your custom module, let's create a block class to handle the super cool logic for obtaining shipping rates! <?php // File: app/code/YourVen...

Setting the ‘continue shopping’ URL to last product’s category page in magento

Here is a code snippet for setting the ‘Continue Shopping’ location to the category listing page of the last product added to the cart. Open the template/checkout/cart.phtml file in your active theme. Place the following code in the foreach loop

(ie. after this line of code)

< ?php foreach($this->getItems() as $_item): ?>

that generates the products list in the cart.

< ?php
$_categories = $_item->getProduct()->getCategoryIds();
$_category = Mage::getModel(‘catalog/category’)->load($_categories[0]);
$url = $this->getUrl($_category->getUrlPath());
Mage::getSingleton(‘checkout/session’)->setContinueShoppingUrl($url);

?>

You are done!

Page 2 of 212
2hats Logic HelpBot