I am currently building an API using the CodeIgniter framework. I have run into an issue and can't find an answer anywhere.
Currently when my end point gets called to post data it requires a URL to be saved to my DB however the format of the URL gets broken when being inserted.
In my request the URL looks like this:
web_url: "https://someurl.com"
However in my DB it looks like this:
https // google.com
Also, when really long URLs are inserted only a small part of the URL is saved. Here is an example:
Original
https://some.service.com/source/update?user=116&subscription=186248&hash=eyJpdiI6IlpSZytyMXI5NFE2XC80Qmc3MTJMREJHVHgyR2dlQU5NakxEbFFWM2Fsb0hNPSIsInZhbHVlIjoiZWdBT0FrZGFYNkw0cllzcXRRcitvMUFRMDNSaFwveVR6bXVRODlSUFM5MUt6aFQzSDNiczJoRUVzdUZ3VE11MHZjWnFnYzNOUUMyTmxmRnpHNVQ0alF3PT0iLCJtYWMiOiI5NjBlMmI3YTZlMzk2MzU1ZmUxMTI3ZTViODQwMTEyYmQ5NTU4OTc5MTg3Mzk1YzBkZWZkODIxOTQzNTNkYmUyIn0%253D
DB:
https //some.service.com/source/update?user=116&subscripti
In my DB the URL field is set asvarchar(1000)
Here is my code that I am using to store the URL:
if ($status == "active")
{
$user_id = $this->post('user_id');
$update_url = $this->post('update_url');
$cancel_url = $this->post('cancel_url');
$account = array("status" => $status,
"user_id" => $user_id,
"update_url" => $update_url,
"cancel_url" => $cancel_url);
$this->db->insert('accounts', $account);
Any ideas how to resolve this?
maybe you can change the datatype of your field to text
I managed to resolve this issue by using $data = $this->input->post(); to get all the data in the post request rather then getting each individual element.
Appears to be working now :)
Related
I save a featured photo to my public/uploads/post and save a string with the photo name to my database. And when I want to delete it, I can't do it. Then I track the error and just realize when I return the value of my photo field in the table, it gives me the photo name with http://localhost:8000 in it
This is my code :
$featured = $request->featured;
$featured_new_name = time() . $featured->getClientOriginalName();
$featured->move('uploads/post', $featured_new_name);
$post = Post::create([
'post_title' => $request->post_title,
'post_content' => $request->post_content,
'featured' => 'uploads/post/' . $featured_new_name,
'category_id' => $request->category_id,
'post_slug' => str_slug($request->post_title)
]);
Then when i try to return it with die() :
die($post->featured);
It give me this result :
http://localhost:8000/uploads/post/1545856404foto.jpg
When i die() it, before save to the database, it work fine :
die($featured_new_name);
The Result :
1545856533foto.jpg
I return another value after i save to database, and it work fine :
die($post->post_title);
The Result :
asdsadadsada
So, before i save to the database, the photo name work fine. But after i save to database and return it, the photo name mess up. That the database work like that? Or it is an error?
It seems like your system has some extra programmatic logic in it that either
Adds http://localhost:8000 to the value before saving it
Add http://localhost:8000 to the variable (via a magic __geter) before returning the value of post_title
This may be something that's in your Post class itself, or may be happening in an event listener. Unfortunately, without more information about your system it's impossible to say for sure what the problem is.
try to save just the name of the photo :
'featured' => $featured_new_name,
and instead use the full photo address in the href attribute of your img tag.
In my laravel project i use hashes in the url to keep track on selections of the user, so they are able to go back to a filter result. I dont want the page to refresh so I DONT UPDATE THE URL with Page=someid (except the hash) the response of the server looks like.
if ($request->ajax()) {
//The page I want to select posted with ajax
$paginaId = $request->input('page');
//some query like
$query = Table::Query();
//get 9 items
$rooms= $query->paginate(9);
//Return the response
return Response::json(View::make('front.rooms.render', array('rooms' => $rooms))->render());
}
The $paginaId represents the selected pagination page. Everything works fine except one part. I cant set the current page of the pagination. I viewed the documentation but couldn't find any solutions.
Try the following:
$rooms = $query->paginate(9, ['*'], 'page', $paginaId);
In this case you can set $paginaId manualy
I'm creating an autocomplete in Laravel 4 using twitter typeahead, but I'm having problems in the matching process.
The JS code:
$('#autocomplete').typeahead({
limit: 20,
name: 'destinatari',
prefetch: '{{URL::to("alumni/posta/utenti")}}',
remote: '{{URL::to("alumni/posta/utenti")}}'
});
The model populates the array like this:
public static function jsonList($idLogged)
{
$users = DB::table('users_data')
->where('userid', '!=', $idLogged)
->select('nome', 'nome_2', 'cognome', 'cognome_2', 'userid')
->orderBy('cognome', 'asc')
->orderBy('nome','asc')
->get();
$i = 0;
$ordered = array();
foreach($users as $u) {
$ordered[$i]['value'] = $u->nome.' '.$u->nome_2.' '.$u->cognome.' '.$u->cognome_2;
$ordered[$i]['tokens'] = array($u->nome, $u->cognome);
$ordered[$i]['userid'] = $u->userid;
$i++;
}
return $ordered;
}
And my controller simply:
return Response::json( Users::jsonList($this->userdata->id) );
The returned json (I see it in Firebug) looks like:
[{"value":"Silvia Miriam Abeyta Carretero","tokens":["Silvia","Abeyta"],"userid":"246"},
{"value":"Malak Julia Abreu Garrido","tokens":["Malak","Abreu"],"userid":"198"},{"value":"Aina Aguado ","tokens":["Aina","Aguado"],"userid":"243"},
{"value":"Jordi Alarc\u00f3n ","tokens":["Jordi","Alarc\u00f3n"],"userid":"308"},
{"value":"Aaron Nerea Alejandro ","tokens":["Aaron","Alejandro"],"userid":"49"},
{"value":"Alexia Alem\u00e1n ","tokens":["Alexia","Alem\u00e1n"],"userid":"306"},
{"value":"Salma Almaraz ","tokens":["Salma","Almaraz"],"userid":"54"},
{"value":"Alma Almonte Nev\u00e1rez","tokens":["Alma","Almonte"],"userid":"101"},
{"value":"Daniela Almonte ","tokens":["Daniela","Almonte"],"userid":"184"}
,....other similar results....]
The problem is that any letter I type only the first name in the list gets autocompleted ("Silvia Miriam Abeyta Carretero") in the input field, but when I type out in full any other name (say, "Daniela Almonte") the field isn't completed and the dropdown keeps showing the whole 20 results, without processing of any kind.
I must say, though, that if I click on a name it gets selected correctly (I'm logging the userid property of the datum ), but still the autocompletion isn't working.
What puzzles me is that If I copy/paste the whole list directly in the JS (taken as is from Firebug), as local property of typeahead() (instead of remote), everything works fine as it should.
What could be causing this? Is it a Laravel response problem? Or is it the typeahead processor (I believe it's in "transport.js" source file, uses jQuery $.ajax()) of the remote url?
It seems like the returned JSON is considered as a single entry, i don't know why since it looks correct to me...
From the typeahead documentation:
$('input.twitter-search').typeahead({
name: 'accounts',
prefetch: 'https://twitter.com/network.json',
remote: 'https://twitter.com/accounts?q=%QUERY'
});
As you can see, the remote parameter must contains the URL with the query parameter.
PHP side, you have to test if the parameter "q" is set and then adapt your request (with a LIKE statement by example) to correctly filter the list.
Otherwise, you can try to remove this remote parameter, maybe it would work with only the prefetch attribute.
I have a question about the optional_param function in a form in PHP (version 5.3.14)
After looking over why certain fields were not being saved in a form I have, I realised that this data...
$checkdata = optional_param('items', array(), PARAM_INT)
Only saves up to 996 places (items) from the form (they are select items and there are many)....
Is this a setting or a something I can change? or alternatively something wrong from my end?
Thanks in advance
Solution : A moodle function (platform i am working with)
Thanks Pekka
this function is a moodle function. It gets a parameter from the current page URL.
For an example url:
http://moodle.dev/course/view.php?id=2&items=4
(this is chosen totally arbitrary)
Using this code:
$checkdata = optional_param('items', array(), PARAM_INT)
Will save the "items" value (here it's 4) in $checkdata. If items does not exist in the url it will do $checkdata = array()
Very newbie question: setting up a Meraki wireless EXCAP walled garden, and will have users land on a terms-of-service.php (simple checkbox)... upon submission, will land on page with other info THEN need to pass to open web. Need to grab first URL, save it, pass to page2.php, and then out to web.
Meraki's example of incoming URL (when user attempts to access wireless):
http://MyCompany.com/MerakiSplashPage/?base_grant_url=https://example.meraki.com/splash/grant&user_continue_url=http://www.google.com&node_id=222222&gateway_id=222222&client_ip=10.222.222.222
Then "When you are ready to grant access to the user, send the user to GET['base_grant_url'] + "?continue_url=" + GET['user_continue_url']. In the case of the example above, this URL would be:
https://example.meraki.com/splash/grant?continue_url=http://www.google.com
Going in circles on how to do this, any suggestions would be much appreciated.
Use rawurlencode to encode the value properly:
'http://MyCompany.com/MerakiSplashPage/?base_grant_url='.rawurlencode('https://example.meraki.com/splash/grant&user_continue_url=http://www.google.com').'&node_id=222222&gateway_id=222222&client_ip=10.222.222.222'
You can also use http_build_query to build the query automatically:
$query = array(
'base_grant_url' => 'https://example.meraki.com/splash/grant&user_continue_url=http://www.google.com',
'node_id' => '222222',
'gateway_id' => '222222',
'client_ip' => '10.222.222.222'
);
'http://MyCompany.com/MerakiSplashPage/?'.http_build_query($query)
Your final URL would be:
$_GET['base_grant_url']."?".$_GET['user_continue_url'];