-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug: site_url() ignores Config\App::$baseURL when not passing $config #7290
Comments
Another test: // default baseURL = "http://localhost:8080/";
$app = config("App");
$app->baseURL = "https://xxx.test.com/";
$app->allowedHostnames = [
"xxx.test.com",
];
return site_url("/login"); // output: http://localhost:8080/login |
Thank you for reporting! But unfortunately, this is not a bug, or we probably cannot fix it. The current URL is determined when a Request object is created. If you want to change the baseURL, please pass the Config object to $app = config("App");
$app->baseURL = "https://test.com/";
return site_url("/login", null, $app); Why do you need to change the baseURL? Can you explain your use case? |
Actually my problem was related to form_open. When I examined form_open function, found site_url. The form_open/site_url functions related to the baseurl cause problems when using dynamic subdomains.
I actually do this definition with filters/pre. At least if it is possible to change it with the filter pre, there will be no problem. |
I think if you set |
How can I use code for domain names such as userX.test.com, random-chars.test.com, can you show an example? Subdomains are set by the user. I think changes need to be made with filters/pre. It also doesn't support regex even. At least that could have been. I cannot upgrade version for this reason. |
How do you know the domain names now? |
I set baseURL in Filters/pre or controller. So I can use form_open, site_url etc. without problem. |
I get it from session or database according to user's choice. Then I edit it with baseUrl. For example, if user chooses kenjis for subdomain, I read from session and edit baseURL to kenjis.test.com. |
Sorry, now the code round the current URI is very complicated. Please try: <?php
namespace App\Controllers;
class Home extends BaseController
{
public function index()
{
$uri = $this->request->getUri();
// Update the current URI object
$uri->setBaseURL('https://test.com/');
$uri->setScheme('https');
$uri->setHost('test.com');
helper('form');
return form_open("login");
}
} |
thank you! |
Since the URI-related code is complicated, difficult to understand, and a bit buggy, However, since it brings breaking changes, I do not yet know when it will be merged or not. |
PHP Version
7.4
CodeIgniter4 Version
4.3.2
CodeIgniter4 Installation Method
Manual (zip or tar.gz)
Which operating systems have you tested for this bug?
Windows
Which server did you use?
apache
Database
MariaDB 10.2
What happened?
site_url() function ignores App->baseURL
Steps to Reproduce
Change config("App")->baseURL and check site_url("test") output.
Expected Output
Output containing the new baseURL (https://test.com/login).
Anything else?
No response
The text was updated successfully, but these errors were encountered: