Codeigniter $_GET in models? - php

I've got a URL parameter I need to get to pass to a PHP MySQL Variable.
Lets say for instance my URL is:
www.facebook.com/?ref=logo
Normally it'd $_GET to get the value of ref. How would I go about doing this in a CodeIgniter model? From what I understand, $_GET doesn't work with CI?

Its in the input class.
$ref = $this->input->get('ref');
Source : http://ellislab.com/codeigniter/user_guide/libraries/input.html

Get works just fine in CodeIgniter. You would access it in a similar way to POST values:
$ref = $this->input->get('ref', true);

Related

Unable to set and get $_GET in cakephp2

I want to have a following condition in my view.ctp. I want to get the parameters like "/?parameters=name&data=1" from a url and have it in my view. I want to set a $_GET. Where can I set it? Controller,Element,lor View? I read multiple tutorials but I still dont get how the $_GET works in Cakephp2. It would be great if you can give me sample or hints for dummies like me.
if(!empty($_GET['parameter'])){
}
$_GET['parameter'] should be $_GET['parameters'] in your code. For your /?parameters=name&data=1

Selecting only Non-file Parameters from Laravel Request

For one of my Laravel Web app I want to log all the Request Parameters(Post as well as Get) in database in Json Format for that I am using $request->all() Method, which results in an exception when user tries to upload any file.
that's why I want a way to select only Serializable Parameters from the request.(for get as well as for post Requests) or a way to select all the request parameters except files.
Request::except([]) will not work for me since in Except method we will have to provide the file parameter names.
In my project, i used this except for many fields like below,
$input = $request->except('first_name', 'middle_name', 'last_name', 'address',...);
It is work fine for me.
I stored all the remain values into $input and store values from that input variable.
Please try this one.
In your case please take this debug code for test once, might be you like it to use in your current work
$allRequestParams = array_map(function($input) {
return !is_array($input) ? $input : false;
}, $request->all());
echo '<pre>';
print_r($allRequestParams);
echo '<pre/>';
die;
Since any of the answer didn't work for me I did lots of reading and some digging about laravel but still I could not find the specific solutions I was looking for, so I did a small hack, instead of using Laravel's Request Object and pulling parameters from there I simply used PHP's built in $_REQUEST parameter.
Eg.
$non_file_parameters = $_REQUEST;
$_REQUEST will have both Get as well as Post Parameters except file Parameters coz in Core PHP for files we have $_FILES super global variable.
Thanks guys for your efforts...

$_GET contains URL string, and the actual query params are emptied -- Codeigniter

I have been working on a web app that has been previously built/worked on by people I have no way of contacting.
I believe we are currently on CI_VERSION 1.7.0.
I've made sure that enable_query / allow_get_array config vars are all true.
I can see the correct values in the header(query string parameters).
Example of the problem below:
//E.g.
//URL: http://www.fakeURL.com/something/stuff?color=blue&gender=boy
var_dump($_GET);
// array(1) { '/something/stuff' => string(0) "" }
Try getting url parameters with build-in class : input.
$p = $this->input->get();
var_dump($p);
Codeigniter recommand to do it this way. For example, you can't get a parameter twice with this function as it is emptied the second time. So we don't know how they manage parameters.
In earlier versions of CI the $_GET array included the requested controller/method after the URL was rewritten (as detailed in this answer), the rest of the info in it was stored in the input class and removed (see the legacy docs).
As the other answer stated, you'll need to use $this->input->get(); which will contain the original $_GET params.
I ended up using this solution, found here: https://stackoverflow.com/a/2283881/1626354
I will say that this is more of a 'work-around' than a solution, but I can't invest anymore time in this right now.
Thanks everyone for your helpful suggestions. Hopefully this will be useful to someone else someday too.

PHP: Sending a request and getting a response

I'm from ASP.NET MVC background and this is first time I'm trying to write something in PHP.
In ASP.NET MVC we can develop models for our data and using the actions that we write we can get them or send them to another action. What I mean is that
public ActionResult Login_Action(LoginModel _Model) {
// Authenticating the user
return RedirectToAction(X);
}
when calling this the url that is shown in the address bar (in case of using GET, if it is POST nothing will be shown after the page name) will be:
www.WebsiteX.com/Login?Username=something&Password=something
The problem is that I don't even know how search for this in google (like by typing what exactly) because in Microsoft side, these are handled automatically the way I described.
But in case of PHP, how can I get the values in the address bar? do I have to get the actual address and then break the values down into arrays?
I'd appreciate any help.
First of all, this seems to be invalid for me: www.WebsiteX.com/Login?Username=something?Password=something The first parameter need to be ? and the others should be &.
Second: You can get your values of your parameters by accessing the $_GET global array.
Eg. for the username echo $_GET["Username"];
Are you using any framework? You should. And then, the Framework will give you the way to do that. In ASP.NET you use a Framework so do the same in PHP.
With vanille PHP you can get the GET values with $_GET['Username']. But please, use a framework.
I think that the most popular are Laravel and Symfony right now.
Example:
In laravel you can bind a parameter to a variable so you can do something like:
//Url: mywebsite.com/user/1/
Route::get('user/{id}', function($id)
{
return 'User '.$id;
});
Which is similar with the ASP.NET example.

how to retrieve HTTP $_GET values with CodeIgniter

i'm stuck with using $_GET variables with CodeIgniter, anyone can help me please?
CodeIgniter comes with three helper
functions that let you fetch POST,
COOKIE or SERVER items. The main
advantage of using the provided
functions rather than fetching an item
directly ($_POST['something']) is that
the functions will check to see if the
item is set and return false (boolean)
if not. This lets you conveniently use
data without having to test whether an
item exists first. In other words,
normally you might do something like
this:
if (!isset($_GET['something'])){
$something = FALSE;
} else {
$something = $_GET['something'];
}
With CodeIgniter's built in functions you can
simply do this:
$something = $this->input->get('something');
Taken from here.
$this->input->get() or $this->input->get_post()
use Input::get():
echo $this->input->get('your_field');
There's no reason that you would be able to use $this->input->get() and not $_GET.
You may be running an older version (less than 2.0.1) that does not have real $_GET "support". Old versions intentionally unset the $_GET array, assuming because it made things "difficult" for the developers. There is a query strings setting in version 1.7.2 that is very confusing and does not do what you'd expect. Newer versions support $_GET as expected.
Please see here for more information if this is the case:
CodeIgniter Enabling Query Strings
I think you must enable 'enable_query_strings = true' first

Categories