If you are using Yii PHP framework you are using one of the fastest PHP frameworks around. Sometimes there are minor things that we want to do and couldn't find a document that is to the point and precise in what you are looking after. This Quick Tip article will show you how to use custom layout for your controllers and actions Controllers When you want to use custom layout other than //layouts/main then you can do it in several different ways Option 1 Include $layout property in your class definition as shown below [crayon-65766a00c03a3237407417/] Option 2 Use init() method of Controller [crayon-65766a00c03a8720414179/] Option 3 Use beforeAction() to overwrite default value of layout property [crayon-65766a00c03a9585846890/] Please note that when you do any of the above layout is applied to all action views. If you however want to only apply a custom layout to one of the controller action then you do it this way Apply custom layout to a Controller Action [crayon-65766a00c03aa199256953/] As we see that in above snippet we are overwriting default value of layout property for just our action Test. Other action views will still be rendered in default or controller layout. I hope that this helps … [Read more...]
Installing Apache thrift, Cassandra 2.x and YACassandra-PDO on CentOS 6.5+
Hello, Well after a long time this is my in length article, the reason I am writing is because of all the stuff I have been gone through building thrift and cassandra-pdo on centOS 6.5 Versions I will be writing about installing latest version of thrift that at time of writing and RnD was 0.9.1, CentOS is version 6.5 64 bit, php 5.3.3, Apache/2.2.15, Cassandra is at version 2.06 which is most stable version for production at the time of writing. Prerequisite Most of the commands will need elevated privileges. You should prefix sudo with every command, I am doing it on test VM so doing it as privileged user root Packages wget, nano are available if not then yum install them as shown below. Of course if you use vi or other util other than wget to download files then skip this [crayon-65766a00c07f5035910959/] Ok so lets get started. When I started building thrift, or cassandra pdo I was getting all sort of errors such as [crayon-65766a00c07f8033010241/] Install Cassandra Installing cassandra is the simplest one, We will be installing it from rpm provided by datastax Open datastax.repo for editing with following command [crayon-65766a00c07f9472959212/] paste following content in editor [crayon-65766a00c07fa072307000/] Install cassandra [crayon-65766a00c07fb523162069/] Above command will also install openJDK but cassandra guys recommend that we should use latest java from Oracle so lets do that now Get into opt directory You can actually choose to be any other directory of your liking [crayon-65766a00c07fc593399340/] Get RPM path for latest jre from http://www.oracle.com/technetwork/java/javase/downloads/index.html I am using jre 8 from http://www.oracle.com/technetwork/java/javase/downloads/jre8-downloads-2133155.html [crayon-65766a00c07fd743298027/] output of java --version would be something like [crayon-65766a00c07fe815966553/] Lets now install Development … [Read more...]
Installing YAF php framework and getting /usr/include/php/ext/pcre/php_pcre.h:29:18: error: pcre.h: No such file or directory on Centos 6+
Hi Guys, Yaf framework appears to be the fastest framework around, logically so because its built with C and compiled in a PHP extension. While installing Yaf, I ran into a problem where it seems like make was complaining about pcre.h missing and progress get halted at make: *** [yaf_router.lo] Error 1 ERROR: `make' failed To solve this first I would like to point out to run a yum update [crayon-65766a00c0b3f968334277/] Secondly make sure you have all of the stuff below [crayon-65766a00c0b43623010355/] and now you should install yaf normally through pecl now as shown below [crayon-65766a00c0b44604024713/] This should work now, and finally you should add the compiled so extension to php.ini file [crayon-65766a00c0b45579896788/] add line below [crayon-65766a00c0b46676868236/] Once this is done restart your apache service and yaf as module will now be available with all its APIs and stuff I hope this helps. If I missed a point or 2 please leave your comment for others to benefit from. Cheers, … [Read more...]
PHP convert timezones
Hi Guys, Just a quick tip here. There are times when you would like to convert a Timezone (say America/New_York) to another Timezone (say UTC) With classes such as DateTime and DateTimeZone available from php 5.2+ this task has become piece of cake. Let me show you how its done. In our example we will be converting America/New_York to UTC time Good thing is that Day light savings are taken into consideration automatically. Code snippet [crayon-65766a00c0c9a674792786/] This is it you can create a function for the above code in your Util class as shown below and get some conversions happening. Generic Function [crayon-65766a00c0c9d880816168/] Usage [crayon-65766a00c0c9e037814750/] Just in case you would like to add to above solution please leave you comments. I hope this helps … [Read more...]
PHP Find pages Indexed by Bing for a domain example
Hi Guys, In the previous post I showed you how to get pages indexed by Google. We used function file_get_contents() to get page as HTML and then parse it to extract the value that we are interested in. This post is pretty much the same logic with only difference that we will be using CURL to get the contents and the parse it Pages indexed by Bing can be quickly checked with query site:yoursite.com and the Number that we are interested in is directly under the search box with value something like this "1231123 Results" This post shows you how to extract that value. The PHP Code snippet Here is a function that you can include in your utility class or just [ltu] [crayon-65766a00c0db5056574326/] [/ltu] Usage Using the above function as per the previous post is quite save and is shown below [crayon-65766a00c0db8005415764/] Bing does not have any API as such that can give you this value. So this is kinda workaround. If I am wrong to say this please correct me. I hope that this helps Cheers. … [Read more...]
PHP Find how many pages are Indexed by Google
Hi Guys, Lately I have been giving undivided attention to my new born daughter so for writing lengthy how-tos, I am finding less time for. But that doesn't mean that I am unable to share some quick how tos. You see, that in many Browser Extensions and/or toolbars that give information on SEO stuff they list page indexed by various search engines such as Yahoo, Bing and Google. An example is shown below. This post shows you how to get that value from Google. The PHP Code snippet Here is a function that you can include in your utility class or just [ltu] [crayon-65766a00c0ebc002843343/] Just in case above doesn't work then you can try out a curl request such as the one shown below, you may need to check if google returns a "document moved" status. In that case you will have to copy whatever Google suggest to make it work. [crayon-65766a00c0ebe253119083/] [/ltu] Usage Using the above function is quite simple and is shown below [crayon-65766a00c0ebf176161143/] This is not very pretty but there is no standard API that I am aware of doing the same. In post to come we will be looking "Find how many pages are Indexed by Bing using PHP" Idea is the same but regular expression will be different. I hope that this helps Cheers. … [Read more...]
PHP Find replace URL in text to HTML Links
Hi Guys, This is kinda straight forward thing to do using Regex magic so let go ahead and build our function which we will call plainUrlToLink() Here is that snippet that you can just copy paste. Don't forget to give this post a +1 if it helped you. The Snippet [crayon-65766a00c10cc207799426/] As you notice that I am not doing a case insensitive replacing that's for a reason. That's that for our function but now lets check how to use it. [ltu] Usage To use this function is simple. It will return a plain text content if [crayon-65766a00c10cf259381993/] Above will print [crayon-65766a00c10d0752263170/] Please note that this function is good for finding links in plain text only and will not work if you pass HTML to it. Also if you want to include FTP URL detection then change you regex to this [crayon-65766a00c10d1999140237/] I hope this helps. Every code has room for improvement, if you think this snippet can be improved please leave your feedback in comments, that will help other readers too. Cheers [/ltu] … [Read more...]
How to get numeric Facebook user ID
Hi Guys, Well I am new to FaceBook Graph API or FaceBook API in general but that doesn't stop me to share if I come up with something useful. Why do you need to know your FaceBook ID? I am a WordPress developer too and there are many social plugins that need to know your FaceBook ID. But that's not the only reason, another reason is exactly why you are reading this. Anyway lets jump on How To First Download the latest PHP SDK from GitHub. Here is the URL https://github.com/facebook/facebook-php-sdk Extract the archive to your current working directory or to somewhere where you place your external libraries. The Code Example [crayon-65766a00c1278773763693/] So as you can see that it is dead simple and I can get my ID from above array as $user["id"] This post actually shows how to use/create a FaceBook Object using your appId and secret If you haven't created your FaceBook Application yet, here is a link to create one https://developers.facebook.com/apps/ I hope this helps Cheers … [Read more...]
How to Lighten or Darken HEX or RGB color in PHP and JavaScript
Hi Guys, Just a thought and following up on my previous post is a function that you can use in your PHP code to brighten or darken a HEX or a RGB color, For color manipulation in JavaScript you can look at this cool library https://github.com/jfsiii/chromath PHP Function Below is the function you can use to make on the fly adjustment to colors [crayon-65766a00c1372777657574/] For sure above function can have less lines but for simplicity and readability I think putting it as above makes sense. Usage - Lightning Colors [crayon-65766a00c1375464062230/] Usage - Darkening Colors [crayon-65766a00c1377100335182/] Now lets check the JavaScript implementation of this function. JavaScript Equivalent Function For Lightening and Darkening HEX or RGB Colors You can definitely do better job with shift operators but I always think of readability of code first. The code below can be shrunk but at least you get the Idea what's happening in a typical way [crayon-65766a00c1379781020644/] Usage 1 - Lighten [crayon-65766a00c137a900783979/] Now lets check how we can use the same function to Darken our Hex or RBG colors Usage 2 - Darken [crayon-65766a00c137c794381936/] I hope this helps. Got a better implementation of these function. I would love to know and this will help my readers too. Share it, leave your comments Cheers … [Read more...]
PHP Convert HEX color code to RGB or RGB to HEX
Hi Guys, This is a quick TIP so that I don't have a burden of not sharing this age old function I wrote ages ago with you :) Anyway there are many occasion when you would like to problematically adjust say brightness, red, green, blue depths for a color code, Let me show you how to do it in PHP PHP Function [crayon-65766a00c15a3318671172/] Above is a simple to use method which you can use and modify as per your needs. Let me show you some example usage for this function Usage 1 - Converting RGB to HEX This example shows how to use the above function to convert our rgb() values to a HEX code [crayon-65766a00c15a6269649092/] Above will print #CC8800 Usage 2 - Converting HEX code to RGB This example usage shows how to utilize above function to convert a HEXadecimal color code to rgb() values [crayon-65766a00c15a7903473710/] Will print [crayon-65766a00c15a8839469018/] As you've got the RGB values you can adjust them to suit your purpose. You can further shrink this function by atleast 3 more lines. I hope this helps Cheers … [Read more...]
Recent Comments