I have a trouble:
I have url of view:
?materials=1&materials=2&materials=3&materials=4&materials=5&materials=6
How can I get it in array throw Yii mechanism?
Yii::app()->request->getParam('materials')
Not working
$_GET['materials']
Too not working
Url is static and can not change
This URL was created https://github.com/Mikhus/jsurl plugin
PHP automatically parses parameter as an array, if it ends by []. (i.e. ?materials[]=1&materials[]=2&materials[]=3&materials[]=4&materials[]=5&materials[]=6) Otherwise you can parse query string manually to solve your issue. Look at this
Related
I am trying to make a dynamically sized form for a web-page I am creating! I have had no issue passing the information needed to the 'action' page through a form (including two arrays), by setting the name of all dynamically created forms to be name[i].
To get the data from the array in the 'action' file, I use the code below, and it works fine:
$_POST['name'][$i]
However, I wish to return the information to the form if there is an error with any of it, and the way I am doing this is with headers.
header("Location: ../originalPage.php?error=error&someValue=".$someValue."&someArray[]=".$someArray);
exit();
Is there anything I need to change for this to return something other than Array()?
Clearly the header is using the $_GET method rather than the form's $_POST method, but why can I only send the array one way?!
Any help would be appreciated!
The issue you have is that you try to concatenate your array to a string, but that does not happen in the way you would prefer. You could convert your array into JSON, like this:
../originalPage.php?error=error&someValue=".$someValue."&someArray[]=".json_encode($someArray));
Read more about json_encode by clicking on the link.
I'm trying out Azure Functions using PHP.
Getting the request information is not working for me.
I've not been able to find any documentation at all with the information of how to use Azure Functions with PHP code.
According to the only couple of examples, it seems that in order to retrieve the input information you need to first get the content of the req variable (or whatever name you assign in the function configuration).
That has the path of the file containing the request information (in theory).
$input_path = getenv('req');
So far, if I check the content of it, I get something like this:
D:\local\Temp\Functions\Binding\e2b6e195-02f7-481b-a279-eef6f82bc7b4\req
If I check if the file exists it says true, but the file size is 0.
Do anyone knows what to do here? Anyone with an example? Does anyone know where the documentation is?
Thanks
Ok, unfortunately there's pretty limited documentation out there for php as you have discovered.
At present, looking at the code might be the best doc. Here is the InitializeHttpRequestEnvironmentVariables function that adds request metadata to the environment for the script languages (node, powershell, php, python).
Important environment variables are:
REQ_ORIGINAL_URL
REQ_METHOD
REQ_QUERY
REQ_QUERY_<queryname>
REQ_HEADERS_<headername>
REQ_PARAMS_<paramname>
I'm assuming you've made a GET request, in which case there is no content (req is an empty file), but you will see that these other environment variables contain request data. If you were to make a POST request with a body then req would have data.
here is a full example parsing a GET request in PHP with an Azure Function :)
https://www.lieben.nu/liebensraum/2017/08/parsing-a-get-request-in-php-with-an-azure-function/
snippet from source:
<?php
//retrieve original GET string
$getReqString = getenv('REQ_QUERY');
//remove the ? for the parse_str function
$getReqString = substr($getReqString,1,strlen($getReqString));
//convert the GET string to an array
$parsedRequest = array();
parse_str($getReqString,$parsedRequest);
//show contents of the new array
print_r($parsedRequest);
//show the value of a GET variable
echo $parsedRequest["code"];
?>
I am trying to implement a search function that will use ajax to query the database when a user types a character into the search box This will bring up any data within the database that begins with the character typed by the user.
I think this line, is your problem;
$this->load->view(array('words' => $wordlist));
You are trying to load an array of views.
The first parameter within the view function, is the name of the file you're trying to load. Like this;
$this->load->view('file_name', $data, true/false)
https://ellislab.com/codeigniter/user-guide/libraries/loader.html
If you want a specific type of data and simple out, you must use header response without $this->load->view just like this:
header('Content-type: application/json');
echo json_encode(array('words' => $wordlist));
Use that, you can easily get data with ajax
I'm using zend framework in my site. URI address one of the page is:
http://mysite.com/controller/action/no/123/date//email//
I expect to obtain the next GET parameters and values:
no=>123
date=>
email=>
It's true on localhost but on the web hosting on obtained:
no=>123
date=>email
It looks like empty values was missed. What can be a reason for this and how I can it fix?
You have issue there is routes have done like first is key and next is value so, in your url have two blank space. change in url something line below.
try like this
http://mysite.com/controller/action/no/123/date/email/
I'm using CodeIgniter and I have a controller which processes uploads using AJAX.
The controller expects to receive the name of the file as paramater, therefore I need to accept almost any kind of possible character in the URL.
My JavaScript encode the file name using encodeURI(), therefore a file named "My File [x].avi" becomes "My%20file%20%5BX%5D.mpg". Everything fine so far.
Problem comes when receiving that parameter into CodeIgniter. The URL looks like
http://localhost/myproject/uploader/upload/My%20file%20%5BX%5D.avi
And the header of the controller:
function upload($param1='') { }
When I print $param1 I got:
string(8) "My_file_"
Even if I use urldecode() it remains the same. Therefore CodeIgniter is eating the encoded square brackets. Any help?
Thank you so much in advance.
I think you have $config['global_xss_filtering'] set to true and so CI is cleaning the vars. If this is the case, you can either set it to false or tweak input->xss_clean function.