Sql Query for getting total number of empty fields in a row…

We can get total number of empty fields in a row in a table…


select SUM((`field1` = '') + (`field2` IS NULL) + ( `field3` = 0) + ...... (`fieldnth` = '')) from tablename where conditions;

Here we use
= ‘ ‘ for fields having field type string like varchar ,chars,text etc..
IS NULL is for field having default value NULL
= 0 is for field define integer type

cakephp pagination with search result

For make pagination compatible with search results

In controller file


<?php
if(isset($this-&gtrequest->data)) {
if (isset($this->request->data['User']['Search']) && ($this->request->data['User']['Search'] != '')) {
$search_keyword = $this->request->data['User']['Search'];
}
}
/*if search keyword is not enter then look for pagination condition params*/
elseif (!empty($this->request->params['named']['cond'])) {

$this->request->params['named']['cond'] = strtr($this->request->params['named']['cond'], '-_, ', '+/=');

$this->request->params['named']['cond'] = json_decode(base64_decode($this->request->params['named']['cond']), true);
if (isset($this->request->params['named']['cond']['search_keyword']) && $this->request->params['named']['cond']['gender'] != '') {
$search_keyword = trim($this->request->params['named']['cond']['search_keyword']);
}
}

if(!empty($search_keyword)){
$cond[] = "Product.productname LIKE '%" . $search_keyword . "'";
$separator['search_keyword'] = $search_keyword;
}

if (!empty($this->request->params)) {
if (isset($this->request->params["named"]["page"])) {
$urlSeparator[] = 'page:' . $this->request->params["named"]["page"];
}
if (isset($this->request->params["named"]["sort"])) {
$urlSeparator[] = 'sort:' . $this->request->params["named"]["sort"];
}
if (isset($this->request->params["named"]["direction"])) {
$urlSeparator[] = 'direction:' . $this->request->params["named"]["direction"];
}
}

$urlSeparator = implode("/", $urlSeparator);
$this->set('separator', $separator);
$this->set('urlSeparator', $urlSeparator);

$this->set('Products', $this->paginate("Product", $cond));

?>

and in ctp file


<?php

$this->Paginator->options(array('update' => '#div_id_for_update',
'url' => array('controller' => 'controller_name', 'action' => 'index', "cond" => strtr(base64_encode(json_encode($separator)), '+/=', '-_,')),
));

?>

Here in controller first we check if user click on search button then check for $this->request->data and set varriable $search_keywrd else check for pagiantion params and set $search_keyword and set pagination varriable and then in ctp file using $this->pagination->options set pagination link url with search condition.

Facebook Share URL

Hello  guys,

Normally we use

<a href="http://www.facebook.com/sharer.php?u=http://yoururl.com&t=your title here target="_blank">Facebook Share</a>

but sometime it not take title from the variable t . For solve this issue you can use

<a href = "http://www.facebook.com/sharer.php?s=100&p[title]=titlehere&p[url]=http://www.yoururlhere.com&p[summary]=your
sumary&p[images][0]=http://www.urltoyourimage.com"  target="_blank">FacebookShare</a>
Here
p[title] => title want to share
p[url] => url want to share
p[summary] = summmary want to share
p[images][n] = images want to share. images may be multiple (n number).

How to get variable from AppController in Other Controllers in cakePHP 2.0

Let We have set a variable “test_Case” in APPController

function beforeFilter(){

$this->set(‘test_Case’ , ‘1’);

}

And We have to use it in Other controller file say TestsController.php

then we will use $this->viewVars.

here we will be used

$test_Case  = $this->viewVars[‘test_Case’];

 

CakePHP Session Issues

CakePHP’s handling of session variables appears very complex .It create confusion when $_SESSION variables are added within code not working. In Core.php we found default

Configure::write(‘Session.cookie’, ‘CAKEPHP’);

and session varriable set by cakePHP app will not be accessed by using $_SESSION. For make it work we have to made change in cakePHP core.php file. We have to add line

Configure::write(‘Session.cookie’, ‘PHPSESSID’);

 Now  $_SESSION vars will be accessed  across both areas.


Note: the session cookie name just needs to correspond to the session name in your php.ini file – the default is PHPSESSID.