What does $this->genlib->ajaxOnly(); mean? - php

I've been trying to learn some php these days and to do that I've been reading some code on github. I saw this one project and decided to read the code from there I keep reading this specific line of code but I don't know what it really means. Can anyone explain it to me? (pardon my noobness)
public function lilt(){
$this->genlib->ajaxOnly();
$this->load->helper('text');
//set the sort order
$orderBy = $this->input->get('orderBy', TRUE) ? $this->input->get('orderBy', TRUE) : "name";
$orderFormat = $this->input->get('orderFormat', TRUE) ? $this->input->get('orderFormat', TRUE) : "ASC";
//count the total number of items in db
$totalItems = $this->db->count_all('items');

ajaxOnly() is a method of the genlib class. It seems the function of it is to display an error message if the incoming request was not made via ajax.

Related

Sending data from AngularJS to PHP for IF-statement in PHP with perhaps in proper syntax?

I am trying to send data from AngularJS to PHP.
I am sending the data from the controller.js of AngularJS.
I am receiving the data through PHP. The data comes well for others variables.
However, I don't know which part is the problem.
My goal is to have the PHP recognize $step_number and run through the IF-statement in PHP, but even though I send wrong data, it works!
Which means,
if the $step_number in PHP is '2', then the IF-statement in PHP should not work as shown in below. But, it runs!
I thought this was the proper way to write the code as other data are being passed to PHP.
Controller.js
$http.post("../crud/projects_update.php",{
step_number : '1', // This one, I am trying to send, but I don't know whether this is not being sent or the problem is occurred in PHP.
project_id : $scope.project_data.project_id // This works in the PHP. It is well sent.
project_title : $scope.project_data.project_title
}
PHP
require_once 'connect.php';
$data = json_decode(file_get_contents("php://input"));
$step_number = $data->step_number; // This should be received from AngularJS and if the $step_number is not matched in the IF-statement, then the function in { } should not work.
if ($step_number = '1'){
$project_id = $data->project_id;
$project_title = $data->project_title;
$conn->query("UPDATE `projects` SET
`project_title` = '$project_title',WHERE `project_id` = $project_id") or die(mysqli_error());
}
Two things need to change:-
1.Change step_number : '1', to step_number : 1,
2.Change
if ($step_number = '1'){ //this is assignment not comparison
to:-
if ($step_number == 1){ // now it's comparison

Return in function not working

I am subscribing to data from a MQTT broker with phpMQTT. I have successfully set up a pub / sub routine based on their basic implementation. I can echo the information just fine inside the procmsg() function.
However, I need to take the data I receive and use it for running a few database operations and such. I can't seem to get access to the topic or msg received outside of the procmsg() function. Using return as below seems to yield nothing.
<?php
function procmsg($topic, $msg){
$value = $msg * 10;
return $value;
}
echo procmsg($topic, $msg);
echo $value;
?>
Obviously I am doing something wrong - but how do I get at the values so I can use them outside the procmsg()? Thanks a lot.
I dont know about that lib, but in that code
https://github.com/bluerhinos/phpMQTT/blob/master/phpMQTT.php ,
its possible see how works.
in :
$topics['edafdff398fb22847a2f98a15ca3186e/#'] = array("qos"=>0, "function"=>"procmsg");
you are telling it that topic "edafdff398fb22847a2f98a15ca3186e/#" will have Quality of Service (qos) = 0, and an "event" called 'procmsg'.
That's why you later wrote this
function procmsg($topic,$msg){ ... }
so in the while($mqtt->proc()) this function will check everytime if has a new message (line 332 calls a message function and then that make a call to procmsg of Source Code)
thats are the reason why you cannot call in your code to procmsg
in other words maybe inside the procmsg you can call the functions to process message ej :
function procmsg($topic,$msg){
$value = $msg * 10;
doStuffWithDataAndDatabase($value);
}
Note that you can change the name of the function simply ej :
$topics['edafdff398fb22847a2f98a15ca3186e/#'] = array("qos"=>0, "function"=>"onMessage");
and then :
function onMessage($topic,$msg){
$value = $msg * 10;
doStuffWithDataAndDatabase($value);
}
Sorry for my english, hope this help !

"Cannot use a scalar value as an array" error in Joomla 3.7.0 (html.php)

I recently updated my Joomla website to 3.7.0. and my contact form is not working properly; it is forever on "sending" status and never becomes "sent".
I do not think there is a problem with the module, but I believe the problematic code below is an issue, because it still persists after deactivating the module.
{
$options['relative'] = isset($options['relative']) ? $options['relative'] : false;
$options['pathOnly'] = isset($options['pathOnly']) ? $options['pathOnly'] : false;
$options['detectBrowser'] = isset($options['detectBrowser']) ? $options['detectBrowser'] : true;
$options['detectDebug'] = isset($options['detectDebug']) ? $options['detectDebug'] : true;
}
I am getting the error "Cannot use a scalar value as an array" in html.php.
Please help; this is my first StackOverflow post.
You can try declaring the variable $options, as an array, before using it.
$options = array();
Hope this will solve your issue. You can also check link, link2
Thanks & Regards,
Kaif

How to return multiple values from a function [duplicate]

This question already has answers here:
Multiple returns from a function
(32 answers)
Closed 6 years ago.
I'm building a script to work with PxPost from Payment Express and I've used their sample code as can be found at http://www.paymentexpress.com/Technical_Resources/Sample_code_-_PHP/PX_Post_-_cURL.aspx
How it works: It's built into an automated script that queries orders from my database, processes them, and returns a value.
My only problem is I want the function to return more than one value, so this is what I've done.
Code to run through functions (Line 201):
$once_complete = process_request($billingID, $order_total, $merchRef);
Which send the payment to be processed, that then gets the returns and processes the XML using the sample code. At the end of the code I've removed all the $html info and just replaced it with the following (line 111):
return $CardHolderResponseDescription.":".$MerchantResponseText.":".$AuthCode.":".$MerchantError;
Which should as far as I understand, return that to what started it. I then want to split those values and return them as strings using the following (line 202):
list($RespDesc, $MerchResp, $AuthCode, $MerchError) = explode(":", $once_complete);
But for some reason that's not working.
I've tried echo-ing the return and it works fine then, but then after that it seems to disappear. What may be going wrong?
You can see the entire page's code at http://pastebin.com/LJjFutne. This code is a work in progress.
Return an array.
function process_request(){
...
return array( $CardHolderResponseDescription, $MerchantResponseText, $AuthCode, $MerchantError );
}
And pick it up via:
$_result = process_request();
$CardHolderResponseDescription = $_result[0];
$MerchantResponseText = $_result[1];
...
Tip: use shorter vars for better reading :)
In your function process_request:
return array($CardHolderResponseDescription, $MerchantResponseText, $AuthCode, $MerchantError);
When calling your function:
list($RespDesc, $MerchResp, $AuthCode, $MerchError) = process_request($billingID,$order_total,$merchRef);
The simplest thing you can do is putting the return values in an array which you can access later:
return array("CardHolderResponseDescription"=>$CardHolderResponseDescription, "MerchantResponseText" => $MerchantResponseText, "AuthCode" => $AuthCode );
And later:
list($RespDesc, $MerchResp, $AuthCode, $MerchError) = $my_return_value

facebook api: count attendees for event (limit problem)

Okay normally I'm all fine about the facebook API but I'm having a problem which just keeps me wondering. (I think it's a bug (Check ticket http://bugs.developers.facebook.net/show_bug.cgi?id=13694) but I wanted to throw it here if somebody has an idea).
I'm usng the facebook PHP library to count all attendees for a specific event
$attending = $facebook->api('/'.$fbparams['eventId'].'/attending');
this works without a problem it correctly returns an array with all attendees...
now heres the problem:
This event has about 18.000 attendees right now.
The api call returns a max number of 992 attendees (and not 18000 as it should).
I tried
$attending = $facebook->api('/'.$fbparams['eventId'].'/attending?limit=20000');
for testing but it doesn't change anything.
So my actual question is:
If I can't get it to work by using the graph api what would be a good alternative? (Parsing the html of the event page maybe?) Right now I'm changing the value by hand every few hours which is tedious and unnecessary.
Actually there are two parameters, limit and offset. I think that you will have to play with both and continue making calls until one returns less than the max. limit.
Something like this, but in a recursive approach (I'm writting pseudo-code):
offset = 0;
maxLimit = 992;
totalAttendees = count(result)
if (totalAttendees >= maxLimit)
{
// do your stuff with each attendee
offset += totalAttendees;
// make a new call with the updated offset
// and check again
}
I've searched a lot and this is how I fixed it:
The requested URL should look something like this.
Here is where you can test it and here is the code I used:
function events_get_facebook_data($event_id) {
if (!$event_id) {
return false;
}
$token = klicango_friends_facebook_token();
if ($token) {
$parameters['access_token'] = $token;
$parameters['fields']= 'attending_count,invited_count';
$graph_url = url('https://graph.facebook.com/v2.2/' . $event_id , array('absolute' => TRUE, 'query' => $parameters));
$graph_result = drupal_http_request($graph_url, array(), 'GET');
if(is_object($graph_result) && !empty($graph_result->data)) {
$data = json_decode($graph_result->data);
$going = $data->attending_count;
$invited = $data->invited_count;
return array('going' => $going, 'invited' => $invited);
}
return false;
}
return false;
}
Try
SELECT eid , attending_count, unsure_count,all_members_count FROM event WHERE eid ="event"

Categories