A Code to $_REQUEST in Codeigniter? [duplicate] - php

This question already has answers here:
How to receive post/get request in codeigniter
(2 answers)
Closed 5 years ago.
In Codeigniter,
$something = isset($_POST['something']) ? $_POST['something'] : NULL; equal to $this->input->post('something');
$something = isset($_GET['something']) ? $_GET['something'] : NULL; equal to $this->input->get('something');
Is there equal code to $something = isset($_REQUEST['something']) ? $_REQUEST['something'] : NULL; ?

for REQUEST method in Codeigniter you have to use like describe below.
$this->input->get_post('some_data');
Let me know if it not works.

You can use bellow methods
$this->input->get_post('some_data'); Read more
$this->input->post_get('some_data'); Read more

Related

Uknown ?? in symfony's public/index.php? [duplicate]

This question already has answers here:
Reference Guide: What does this symbol mean in PHP? (PHP Syntax)
(24 answers)
Closed 4 years ago.
While I was looking over symfony's public/index.php I came across the following snippet of code:
$env = $_SERVER['APP_ENV'] ?? 'dev';
$debug = (bool) ($_SERVER['APP_DEBUG'] ?? ('prod' !== $env));
Therefore I performed the following searches:
https://duckduckgo.com/?q=php+%3F%3F&t=canonical&ia=web
https://duckduckgo.com/?q=php+%24var+%3F%3F+%24var2&t=canonical&ia=qa
https://secure.php.net/manual-lookup.php?pattern=%3F%3F&scope=quickref
But still I cannot figure out what the operator ?? actually means. Can you provide me info regarding this operator/syntax ?
it's shortest version of
$env = isset($_SERVER['APP_ENV']) ? $_SERVER['APP_ENV'] : 'dev';
was added in PHP 7

How to remove file url when calling var_dump() function [duplicate]

This question already has answers here:
Why does var_dump show filename and line number?
(2 answers)
Closed 5 years ago.
so here in the below code im calling nytimes api
<?php
function rpnyt_article_get_result( $rpnyt_search , $rpnyt_key ){
$rpnyt_url = 'https://api.nytimes.com/svc/search/v2/articlesearch.json?q='.$rpnyt_search.'&api-key='.$rpnyt_key ;
$json_feed = wp_remote_get($rpnyt_url);
var_dump($json_feed[ 'body']);
}
?>
im getting response back as expected but that includes file url from where im calling this function like /home/ubuntu/XXXXXXXXX/xxxxxxxxxxxx/plugins/XXxxx/includes/rpnyt-news-content.php:8:(see image)
Try var_export() instead of var_dump().
http://php.net/manual/en/function.var-export.php
Consider using
echo(json_encode($your_thing));

Replace Question Mark & Variables in URL into Slash in PHP [duplicate]

This question already has answers here:
URL rewriting with PHP
(5 answers)
Closed 5 years ago.
I'm looking for a way to turn variables in a URL after the question mark into a simple notation with a slash.
For example: I would like to make it possible to enter this link:
http://localhost/MySite/View?Name=Test
in this form into the browser
http://localhost/MySite/View/Test
The MySite then should recognize "Test" as the Name variable. So basically the two links should give the same result.
How it will be done ?
You should read your request uri and search for the third subdirectory:
$view = $_GET['Name'];
if(!isset($view) && isset($_SERVER["REQUEST_URI"])) {
$uriArray = explode($_SERVER["REQUEST_URI"]);
if(count($uriArray) == 3 && $uriArray[1] == 'View') {
$view = $uriArray[2];
}
}

PHP nested IF ELSE Short hand [duplicate]

This question already has answers here:
Stacking Multiple Ternary Operators in PHP
(11 answers)
Closed 6 years ago.
I'm trying to display a correct results based on the value of the variable but I'm using a short hand,
I have tried the following but its seems to ignore the first check even if the value is correct.
(!empty($national_ID_number)) ?
$national_ID_number :
(!empty($foreign_ID_number)) ?
$foreign_ID_number :
$temporal_permit_number)
Thanks
It's populating correctly for me with this code, you seem to have added additional bracket.
$national_ID_number = '';
$foreign_ID_number = 2;
$temporal_permit_number = 3;
$finalID = (!empty($national_ID_number)) ? $national_ID_number : (!empty($foreign_ID_number ) ? $foreign_ID_number : $temporal_permit_number);
echo $finalID;
I just went for a bit deep research - apparently each condition needs to be inside brackets and the below fix works fine.
(!empty($national_ID_number)) ?
$national_ID_number :
((!empty($foreign_ID_number)) ?
$foreign_ID_number :
$temporal_permit_number));
Reference and PHP Operator precedence

PHP pass second argument into function [duplicate]

This question already has answers here:
How to set optional parameter to default without passing it?
(4 answers)
Closed 5 years ago.
I have a function like this:
function myfunc(arg1=false, arg2=false){
//some code here......
}
If I only want to pass arg1 into the function, I can write like this myfunc("arg1 only variable"). But how can I pass only arg2 into the function?
Thank you.
try like this,
myfunc(false, $arg2);
Any of the following would be legal calls to your function:-
myfunc();
myfunc(true, true);
myfunc(true, null);
myfunc(null, true);
myfunc(null, null);

Categories