php - understanding this->request->post [closed] - php

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I'm studying someone else's code in order to learn php,html and something I don't understand is this:
if (isset($this->request->post['eid'])) {
$eid = $this->request->post['eid'];
} else {
$eid = '0';
}
How exaclty is the value of the field eid passed to the php file that just opened and how can I use this mechanism to pass values to other files? And secondary..what is different when get is used instead of post at the same statement?

The -> arrow operator is used to get variables and functions that belong to an object.
In this case, $this is an object and you're getting the varible request from that object. That variable contains another object which has a variable post. That variable is an array and you're getting the value with index "eid" from that array using post['eid'].

$this->request->post['eid'] is same as $_POST["eid"] in simple words.
$this->request->post['eid'] is used in the frameworks. $_POST is the array of values which you get on form submission.

Related

How do you map HTTP inputs to functions? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I have a script, let's call it myScript.php. It's one of several scripts.
I want to pass certain things to it via the HTTP address, like this: …/myScript.php?format=xml&action=courses where xml is the format and the action is a query some courses in my database.
But I want also to be able to assign …/myScript.php?format=json&action=courses in the same script.
How can I do this?
You can reference any parameters passed in the url like so in php: $_REQUEST['format'], $_REQUEST['actions']. You can then assign them to a variable and change that variable in your script.
fetch('./myScript.php?format=xml&action=courses')
$_REQUEST['format'] //xml
$_REQUEST['actions'] //courses
REQUEST is the general method but you can also use GET. Refer to this for more info: https://stackoverflow.com/a/1924958/11945488
$_REQUEST=array_merge($_POST,$_GET,$_COOKIE);
in native php global request variable include get post and cookie ..
You should get parameters with global variable $_GET,
if you does $_REQUEST maybe can confusion php

How to insert php post name into a variable? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I have a post value named $_POST['John'] and I want to insert the post name "John" into a variable but not its value. How can I achieve this? Code Sample:
$_POST['John'] = "value";
array_keys is PHP function which is returning the keys from an array, you have only single array than we can use 0 as the key. if you have more than one array element you can use loop.
You can use array_keys as you mentioned there is one parameter use
$a = array_keys($_POST)[0];
https://3v4l.org/NUkkL

Object Declaration on a array variable [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
While Looking into a PHP Plugin i saw a line ,
$this->banks[0] = new Population();
It seems like they are declaring a object in a array variable. What is the use of it?
For what you described, it seems they're using a common pattern called Singleton that is useful in the way that you have all objects and their states accessible from only one common object.
It all depends on how the PHP plugin works.
The advantage of using a class instead of the array allows you to create function for a better data manipulation (e.g. a population class could have a function getPersonByName or getPersonsByAge which makes it easier instead of making a new loop each time.

PHP: Elements of array used during page render? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I have a language system written in PHP. It loads phrases from the database to the array and then displays some of them during the page render. Right now it looks simple:
<h1><?=$phrase['phrase_callsign']?></h1>
What I need is to know, what particular keys was used during the page rendering procedure.
I have a special function to count and log phrases, so code looks like this:
<h1><?=$this->model->phrase('phrase_callsign')?></h1>
What I'm asking for, is there are something already built in in PHP instead of the handwritten function to display array keys used? Personally I haven't found anything yet.
Thanks.
If I understand correctly you want to record the keys you are using to retrieve callsigns from the array. I would just define a regular function where you pass in the callsign. It adds it to another array, logs it, and then return the callsign value.
function getCallsign($callsign) {
// log callsign
array_push($callsigns, $callsign);
return $phrase[$callsign];
}
If you want to make a list of all the callsigns that were displayed, just push them onto a variable:
<h1><?php $all_callsigns[] = $phrase['phrase_callsign']; echo $phrase['phrase_callsign']; ?></h1>

Using a PHP if statement to change a link dynamically [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I am trying to create a form using the post method with a php script. Everything works except where it lets users choose between multiple packages.
On the confirmation page, there is a Pay Now button that I want to lead to a different Paypal payment page based on which package they choose on the form (the confirmation page is combined into the php script file). The problem is when I create the If statements in the script to say if $variable = "This" then $pay_link = this, a href="<?php echo($pay_link); ?>" it changes the $variable to "This" instead of just checking if it = "This".
Is there any way to do what I am trying to achieve?
It sounds like you are trying to do this:
if ($variable = "This")
A single equal is the "assignment" operator, so you are basically saying:
Assign "This" to $variable, then if $variable is a non-fasle-y value, do something.
What you want is ==, which is the "boolean comparison" operator
if ($variable == "This")
That should do the trick.

Categories