0

I have a method which returns all jobs by category. The problem it's when i have spaces in the category name. How could I access those results?

for ex if i access http://localhost/management_system/Job/get_jobs_by_cat/Architecture it will return all the jobs from the Architecture category.

But when i try to access the category Information Technology I can't do it while I have spaces into the url, so I've tried with _ - and i didn't get any response.

How I can fix this issue?

3
  • You can use rawurlencode php.net/manual/en/function.rawurlencode.php Commented Feb 19, 2018 at 11:44
  • could you give me an example please? Commented Feb 19, 2018 at 11:49
  • Slugify category name on insert. Commented Feb 19, 2018 at 12:22

2 Answers 2

0

You would likely want to use urldecode() to decode the url parameters in the controller function processing this logic. In your controller, do something like this:

$jobCat = urldecode($this->uri->segment(4));

Then, you would pass $jobCat to your model.

Here are some other Stack Overflow links that might help your cause.

How to pass parameters with space to controller from URL in codeigniter?

Php - Codeigniter url spaces

what is the use of $this->uri->segment(3) in codeigniter pagination

Sign up to request clarification or add additional context in comments.

7 Comments

With urlencode I have some issues when i have to encode the categories with / in the name, ex Accounting / Finance becomes Accounting+%2F+Finance which gives me the fallowing error Object not found! The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error. If you think this is a server error, please contact the webmaster.
@TerchilăMarian the error is likely because it is a forward slash (/). The forward slash makes it think there is another segment in the URL. You might need to replace that in the output somehow.
So if i wanna make it i have to replace the / with something else? That's the only way?
@TerchilăMarian you might be about to adjust the route in routes.php or .htaccess file to get the desired result without replacing anything.
|
0

You need to URL encode Information Technology.

$category = 'Information Technology';
$encodedCategory = rawurlencode($category);
$url = 'http://localhost/management_system/Job/get_jobs_by_cat/' . $encodedCategory;

echo $url;
// http://localhost/management_system/Job/get_jobs_by_cat/Information%20Technology

1 Comment

With urlencode I have some issues when i have to encode the categories with / in the name, ex Accounting / Finance becomes Accounting+%2F+Finance which gives me the fallowing error Object not found! The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error. If you think this is a server error, please contact the webmaster.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.