Welcome Guest, Not a member yet? Register   Sign In
Somewhat confused about URL Helper
#1
Question 
(This post was last modified: 04-06-2023, 01:59 AM by joho.)

I've only been playing with CI for a few days, so forgive me if this turns out to be a case of ignorance or misreading something.

Regarding the URL Helper functions, why is the "CI master-file" (index.php) often included in the output? Wouldn't it be far more useful if I was actually getting URLs back that matched what the browser things/uses? I mean, URL functions are most often used to create an application that is self-contained, to allow for a dynamic configuration scenario (as opposed to hard coding value), no?

My playground environment is https://mydomain.com/ltest
The current section I'm playing with is https://mydomain.com/ltest/subsection
The current route I'm playing with is https://mydomain.com/ltest/subsection/edit

So...

site_url() returns "https://mydomain.com/ltest/index.php"
base_url() returns "https://mydomain.com/ltest"
index_page returns "index.php"
url_to('subsection::edit') returns "https://mydomain.com/ltest/index.php/subsection/edit"

If I were to use any of these returned URLs in, for example, a form, I would still have to manually override things, or force things, which I don't want to. I want the application to be able to figure out what a correct and absolute URL is.

I realize I can do manual replacing, remove "index.php" from the returned data, and so on. But I'm curious as to the reasoning behind the logic that is in place now.

I guess I was thinking more along the lines of these:

$_SERVER['REQUEST_URI'] = "/ltest/subsection/edit"
$_SERVER['HTTP_HOST'] and $_SERVER['SERVER_NAME'] = "mydomain.com"

To have something I could put in a <form method="post" action="..."> to get an absolute (and correct) URL.

I do realize that most "apps" don't live in a sub-directory or "subsection", and that it may be an edge case, but I'd still like to make the app dynamically adjust for this possibility.

Maybe I configured something wrong.

(This is using PHP 8.1.2 with Nginx)

I did find that by exposing 'request_uri' as a parameter from the controller to the view, .e.g.
Code:
$data['request_uri'] => $this->request->getUri()

I can do this in the view, so I guess that works better for my purposes.
Code:
<form method="post" action="<?= $request_uri ?>">
..
</form>

That gives me the URL I want for the form action, which is https://mydomain.com/ltest/subsection/edit
Reply


Messages In This Thread
Somewhat confused about URL Helper - by joho - 04-06-2023, 01:31 AM
RE: Somewhat confused about URL Helper - by joho - 04-06-2023, 02:56 AM



Theme © iAndrew 2016 - Forum software by © MyBB