• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
beta 2 - base_url() inconsistent in namespaces

#1
Greetings.  Is this a bug or am I missing something basic?

base_url() is correct when referenced in the app namespace, but is incorrect in other namespaces (i.e. modules).  
site_url() is correct in both namespaces.

Here is a minimal example of the code I used to create, use, and route modules and the "quirk".

PHP Code:
SETUP:
App/Config/App.php:
       public 
$baseURL 'http://localhost/ci4/';  
       
// the paths.php file has all the directories changed to the real directories on the C: drive
       // The public/index.php was modified to point to the actual config/paths.php file 
       // and index.php was then copied to the localhost directory.  That is the only file on localhost/ci4.

App/Config/Autoload.php:
$psr4 = [
'    Config'       => APPPATH 'Config',
    
APP_NAMESPACE => APPPATH               // For custom namespace
    
'Auth'          => ROOTPATH 'Auth',      // For the module
    
'App'         => APPPATH               // To ensure filters, etc still found,
];

App/Config/Routes.php:
$routes->add'login' 'Auth\Controllers\Login::index');
$routes->add'logout''Auth\Controllers\Login::logout');
$routes->add'/'     'App\Controllers\Home::index');


APPLICATION:

App/Controllers/Home.php:
// site_url() and base_url() both = "http://localhost/ci4/" here
// Make sure user is logged in first: 
$sec = new \Auth\Models\Secmgmt(); 
$security $sec->sec_check();
// if not...
if (!$security['logged_in']) $this->response->redirect(base_url('login'));


Auth/Controllers/Login.php:
// Login form is processed and all is good.  Return to Home now.
// if ($data['logged_in'])  $this->response->redirect(base_url("/"));  ===> goes to 'http://localhost/' and not routed
   
if ($data['logged_in'])  $this->response->redirect(site_url("/"));  ===> goes to 'http://localhost/ci4/'  Yay

Any ideas why the redirect to base_url() fails here?  Same result as $this->response->redirect('/').

Also, it seems that the response class is not available from any models code.  Is that by design, can I redirect in the model code, or did I goof up there too?


Cheers.
Reply


Messages In This Thread
beta 2 - base_url() inconsistent in namespaces - by devops - 04-12-2019, 11:23 AM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.