Codeigniter's redirect is not passing variable data - codeigniter

I have a form to update some profile information. After making changes when the user clicks on the submit button my to be redirected to the profile page.
so after inserting the updated information into database I have the following code to redirect to the profile page:
database query goes here...
redirect('studentprofile/get/$id');
Here the $id is the the profile id and "get" is the function and "studentprofile" is the controller. But this is not working at all. It seems like the "redirect" is not getting the value of $id.
When the user submits data it shows an error saying "The URI you submitted has disallowed characters." and the URL looks like this
http://localhost/sundial/studentprofile/get/$id
would you please kindly tell me what is wrong with my script? Just for your information I am using Codeigniter
Thanks in advance :)

You need the redirect path string to be in double quotes:
redirect("studentprofile/get/$id");
or write it like this:
redirect('studentprofile/get/'.$id);

You are using single quotes use single quotes instead and btw that is not an issue of CodeIgnitor. Read more about strings: http://www.php.net/manual/de/language.types.string.php#language.types.string.syntax.double

Related

Laravel 5.7 Passing a value to a route in a controller

My controller posts a form to create a new page. After posting the form I need to redirect the user to the new page that will have the contents for that page that were entered in the previous form. If I simply do return view('mynewpageview', compact('mycontent')); where my mycontent is the object used to execute the $mycontent->save(); command, I carry the risk for someone refreshing the url thus posting the same content twice by creating a new page.
Instead I would like to redirect the user to the actual page url.
My route is
Route::get('/newpage/{id}', 'PageController#pagebyid'); and if I use return redirect()->route('/newpage/$pageid'); where $pageid = $mycontent->id; I get Route not defined error.
What would be the solution either to stop someone from resubmitting the content or a correct syntax for passing the parameter?
The correct answer that works for me is -
Give your route a name in the routes file
Then pass the parameters with an array as shown below in the controller.
return redirect()->route('newpageid', ['id' => $pageid]);
With basic (unnamed) routes, the correct syntax was return redirect('/newpage/'.$pageid);
You have already found out you can alternatively use named routes.
Last but not least, thanks for having considered the "double submit" issue! You have actually implemented the PRG pattern :)

QTP/UFT change or modify URL during test execution

I have an UFT script, in the second action, i need change the URL DURING test execution, because need to permissions obtained in login in first URL for work in second URL. Don't work in a new sheet or window.
Somebody can help me?
This is my code:
'Int user
Browser("Inicio").Page("Inicio").WebEdit("userid").Set "user"
Browser("Inicio").Page("Inicio").WebButton("Entrar").Click
Wait 3
'Int Pass
Browser("Inicio").Page("Inicio").WebEdit("password").Set "pass"
Browser("Inicio").Page("Inicio").WebButton("Aceptar").Click
Wait 10
' Change URL for work:
'In this point, i need help
Not clear what you asking. What my guess is
You need to login which you have done already.
Get current URL from browser so that you can get a particular string from URL to put it in another URL
If so, then you can use GetROProperty of browser page. So code would be like
Browser("Inicio").Page("Inicio"). GetROProperty ("URL")

code igniter url doubling

I'm having an issue where when I submit a form where the submit URL the just appends to the existing URL instead of replacing it.
It is supposed to be:
localhost/DataConnect/index.php/sites/MakeEdit/1
But instead I get:
localhost/DataConnect/index.php/sites/EditSite/localhost/DataConnect/index.php/sites/MakeEdit/1
I open the form with:
echo form_open('sites/MakeEdit/'.$site['ID'],$attributes,$hidden);
So I.m not real sure where I am going wrong. If there is any more information I can provide please let me know. Thanks in advance.
try:
echo form_open(base_url().'sites/MakeEdit/'.$site['ID'],$attributes,$hidden);
and don't forget to call the url helper on your controller:
$this->load->helper('url');

way to pass variable through url in codeigniter

I got a big search module in my Codeigniter project. Well simply I am passing variable to a view like
<a href=<?php echo site_url('controller/view/1'); ?>>View List</a>
And fetching its data in controller like
$id=$this->uri->segment(3);
For pagination
http://wwww.site.com/controller/view/<filter id>/<page from>
This is working perfectly in the case of simple query.
Now I got some more filter quires like
Country
State
City
Customer type
etc etc
then the url should be
http://wwww.site.com/controller/view/1/id2/id3/i4/id5
Is this the correct way to do the process ? If not please give a little advice...
I am new to codeigniter
The problem you are facing i have recently found a solution for this.
When you are first sending parameters through url use POST instead.
When you get the parameters you can pass them to session in a variable
type. Next time when you paginate get the type value from session and
put it in your query to get the desired result.
If you have more than 1 parameters you can put them in sessions and
unset them on certain conditions so that they are not called in every query.
I think the best approach here is to create another method in the controller something like filtered_view that accepts a filter_id and a page number, and that methode will fetch the data from the database with the provided filter and you'll use your pagination class as usual.
Hope this help.

hide passed IDs in URL

noob question. when I pass an id in the route to query my DB, is there a way to prevent the actual id from showing in the URL in browser.
If not, is there a way to prevent the user from changing the id in the URL and access other information?
Some sort of validation you get from clicking the link on the previous page or something.
I hope this make sense.
You could retrieve your record with an hash instead of the id directly.
You can use package like https://github.com/mitchellvanw/hashids (there must be some others)
Also, if you just want to hide it, you can POST it to your page. Don't forget that users can still change the form informations.
U can use base64_encode() and base64_decode to hide url from users and preventing them to change.

Resources