How to change the php version for the console

Many a times when you view the php version in the browser by displaying the phpinfo() information and the php version that is displayed when you see by typing the command “php -v” in the console or command prompt, You will notice that there is difference in the two.

So how  to set the php version same as the version that you see in your phpinfo( ) function in the browser.

Step 1: Find the path to the executable of the php from the phpinfo() displayed in the browser. For example, if you have ampps installed you will find the path as “/Applications/AMPPS/php-7.1/bin/php”. 

Incase you have multiple version of php configured then choose the binary/executable path to the required version of php.

For example for php5, the path would be “/Applications/AMPPS/php5/bin/php”.

Step 2: Setting the php version for the console

Once you have decided upon the required php version for your console application execute the below command.

alias php=’/Applications/AMPPS/php-7.1/bin/php’ => This will set your php version to 7.1 for you console command line instruction.

Similarly for php5

alias php=’/Applications/AMPPS/php5/bin/php’

To make this work,You need to double check the location of the required php executable path, then only it will work. If you don’t have the required version installed. you could installed it as per your need and the operating system you are using.

 

Ajax call using jquery

function makeAjaxRequest(data1,data2,.....,datax){
    $.ajax({
        'type':'POST',
        async: false,
        url: 'http://www.example.com/some_request_url',
        data:{param1:data1,param2:data2,....,paramx:datax},
        success : function(response) {
            console.log(response); // Using this you can check the posted data in browser console window
            return true;// you can process and return the response as required
            //location.reload(); // or you may reload the current page also
        },
        error: function (jqXHR, exception) {
            // If some error is returned, you can check the details below
            var msg = '';
            if (jqXHR.status === 0) {
                msg = 'Not connect.\n Verify Network.';
            } else if (jqXHR.status == 404) {
                msg = 'Requested page not found. [404]';
            } else if (jqXHR.status == 500) {
                msg = 'Internal Server Error [500].';
            } else if (exception === 'parsererror') {
                msg = 'Requested JSON parse failed.';
            } else if (exception === 'timeout') {
                msg = 'Time out error.';
            } else if (exception === 'abort') {
                msg = 'Ajax request aborted.';
            } else {
                msg = 'Uncaught Error.\n' + jqXHR.responseText;
            }
            $('#post').html(msg); // return the error response in your html page or process it further as required
        }
    });
}

 

Yii2 how to set custom value for checkbox in gridview widget

In Yii2, while you use gridview widget to display your table data, for performing any operation on the record by selecting the checkbox, gridview assign the value of the first column retrieved from your the result set.

But you need to set some different value to the checkbox, so to do that you can use the below code

GridView::widget([
	'dataProvider' => $dataProvider,
	'filterModel' => $searchModel,
	'columns' => [
		['class' => 'yii\grid\SerialColumn'],
		[
			'class' => '\kartik\grid\CheckboxColumn',
			'checkboxOptions' => function($model, $key, $index, $widget) {
				return ["value" => $model['id']]; // this can be substituted with any column value of your result data
			},
		],
		'name',
		['class' => 'yii\grid\ActionColumn'],
	],
]);

instead of the default one

GridView::widget([
	'dataProvider' => $dataProvider,
	'filterModel' => $searchModel,
	'columns' => [
		['class' => 'yii\grid\SerialColumn'],
		[
			'class' => '\kartik\grid\CheckboxColumn',
			'mergeHeader'=>false
		],
		'name',
		['class' => 'yii\grid\ActionColumn'],
	],
]);

issue with submit form in ajax success response

Usually when we try to submit the form after ajax call on success response, the form does not’t get submitted.

Like for example in below code:-

$.ajax({
type : “POST”,
url : “to/some/url”,
data : {
userName:userName,
mobileNumber:mobileNumber,
otp:otp
},
dataType : “json”,
success : function(data)
{
if(data.result == true) {
jQuery(“#form_id”).submit();
}else {
return false;
}
}
});

Now why this occur. Since you are calling the submit function from the ajax response, you need to remove the “submit” handler before submitting the form again. I.E. You need to submit the form without doing the ajax call again. Refer below:-

$.ajax({
type : “POST”,
url : “to/some/url”,
data : {
userName:userName,
mobileNumber:mobileNumber,
otp:otp
},
dataType : “json”,
success : function(data)
{
if(data.result == true) {
// Submit this form without doing the ajax call again
jQuery(“#form_id”).unbind().submit();
}else {
return false;
}
}
});

 

How to search in specific content type in drupal 7

Suppose you have created a content type named as “testimonial”. Now the requirement is to for search for a value “hello” under field name “title” then you can do so by using the below query. Please make sure that you have the “Entity API”  module enabled.

 


$searchkeyword = $_REQUEST['keyword'];
$query = new EntityFieldQuery();
$result = $query->entityCondition('entity_type', 'node')
->entityCondition('bundle', '[The machine name for your content type]') // in our case it is "testimonial"
->propertyCondition('title', $searchkeyword)
->propertyCondition('status', 1)
->fieldCondition('field_active_status', 'value', 'active',"=") // here you have to define your where condition on additional fields if required
->execute();