url encode |
I've a controller below. When I redirect the parameter is getting decoded and CodeIgniter can't match the URL and I get a 404. What's going on here?
My route is: PHP Code: $routes->get('/operations/path-item/(:segment)', 'Operations::path_item/$1'); PHP Code: public function data()
Simpler is always better
Why do you use urlencode() for $path?
(09-28-2022, 08:39 PM)kenjis Wrote: Why do you use urlencode() for $path? Because path will equal something like '/data/reports/some_file.txt' so <a href="/operations/path-item/<?= $path ?>">click me</a> will result in <a href="/operations/path-item//data/reports/some_file.txt">click me</a> (It appears in some cases that CodeIgniter url decodes and url encodes html form data for you. I'm not sure if I like that.)
Simpler is always better
Sorry, I don't get what you say.
In my opinion, the code should be: Code: base_url("/operations/path-item/$path")
(09-29-2022, 06:54 PM)kenjis Wrote: Sorry, I don't get what you say. The $path var = '/data/reports/some_file.txt' therefore the url will = '/operations/path-item//data/reports/some_file.txt' and the url will not work. Need to encode $path so url will = '/operations/path-item/%2Fdata%2Freports...' then this will work.
Simpler is always better
%2F equals /
/operations/path-item//data/reports/some_file.txt and /operations/path-item/%2Fdata%2Freports%2Fsome_file.txt are the same. If you want to capture a part of a URI that has slashes, you need to use (:any): https://codeigniter4.github.io/CodeIgnit...aceholders
(09-29-2022, 11:32 PM)kenjis Wrote: %2F equals / No. :any allows an arbitrary number of segments. That's not what I want. I need '/data/report/some_file.txt' to be one segment. To do so I need to url encode it. CodeIgniter is decoding it for some reason.
Simpler is always better
(09-30-2022, 09:24 AM)donpwinston Wrote: No. '/data/report/some_file.txt' is not a segment, but three segments. The solutions I can come up with are: 1. Use query string, not URI segment 2. Use another encoding method that is safe as URI, not URL encoding CI4 probably encodes/decodes URI string for normalizing the URI.
(09-30-2022, 02:08 PM)kenjis Wrote:Yes, I've resorted to using ?path=/data/reports/some_file.txt(09-30-2022, 09:24 AM)donpwinston Wrote: No.
Simpler is always better
|
Welcome Guest, Not a member yet? Register Sign In |