Long time no ZF2 post, but here is something interesting peace of code that can solve cache problems present in most of the projects. I am assuming that, the reader knows how to create custom cache Factory in ZF2. Step 1. Edit your existing cache factory. See Line 35. namespace Application\Factory; use Application\Factory\CacheProxy; // Or […]
As always we go straight to coding. Download how-to-create-google-login-on-my-site-with-openid-in-5-min.zip
Right to the example… $identifier = spl_object_hash(function(){ // some function content }); Simple as that. Suggestions or problems ? Write a comment.
function csvToArray($file){ $rows = array(); $headers = array(); if(file_exists($file) && is_readable($file)){ $handle = fopen($file, 'r'); while (!feof($handle) ) { $row = fgetcsv($handle, 10240); if(empty($headers)) $headers = $row; else if(is_array($row)) $rows[] = array_combine($headers, $row); } fclose($handle); } else { throw new Exception($file.' doesn`t exist or is not readable.'); } return $rows; } Simple as that. Suggestions […]
In this tutorial you will learn how to setup zend framework 2 acl and check if user has access for current route. If you don`t have testing project , download one from here. Add file module.acl.roles in application/config/ Tip: In fact role resources may be zend framework 2 routes. return array( 'guest'=> array( 'home', 'login', […]
A bit hard this one , but there is a way to convert EU odds to UK odds in php. function eu_to_uk_odds($odds){ if(floor($odds) !== $odds){ $odds = (string) round($odds – 1,2); $oddsArr = explode('.',$odds); $f1 = (int) $oddsArr[0].''.$oddsArr[1]; $f2 = str_pad('1', ($f1 >= 10 ? 3 : strlen($f1) ),'0',STR_PAD_RIGHT); $minDel = $this->gcd($f1,$f2); $odds = $f1 […]
A simple solution to count days between 2 dates is using DateTime method since php 5.3 function getDaysBetweenDates($from,$to,$addLastDay = false){ $d1 = new \DateTime($from); $d2 = new \DateTime($to); if($addLastDay){ $d2->add(new \DateInterval('P1D')); } return $d1 -> diff($d2)->days; } echo getDaysBetweenDates('2013-03-01','2013-03-11'); //10 echo getDaysBetweenDates('2013-03-01','2013-03-11',true); //11 If you need to count the last day too , just pass […]
This simple function will allow us to control php performance at level we need. /** * Calculates the processor load in % * @see sys_getloadavg * @author Ivan Gospodinow * @site ivangospodinow.com * @date 07.02.2013 * @param int $coreCount * @param int $interval * @return float */ function systemLoadInPercent($coreCount = 2,$interval = 1){ $rs = […]
$areSame = (serialize($ob1) === serialize($ob2)); This easy way of comparing two objects in php.It will take in account object variables. Example : class ob1{ public $number = 1; } class ob2{ public $number = 1; } $areSame = serialize(new ob1()) === serialize(new ob2()) //$areSame = true; class ob1{ public $number = 1; } class ob2{ […]