Skip to content

Bug: Request::$uri and current_url(true) behave differently #7296

Description

@kenjis

CodeIgniter Version: 4.3.2

<?php

namespace App\Controllers;

class Home extends BaseController
{
    public function index()
    {
        $uri1 = $this->request->getUri();
        var_dump($uri1);

        $uri2 = current_url(true);
        var_dump($uri2);
    }
}

1. baseURL without subfolder

From: https://forum.codeigniter.com/showthread.php?tid=86872

baseURL: http://localhost:8080/null
segments: []['index.php']
path: /'/index.php/'

Details
/Users/kenji/work/codeigniter/official/CodeIgniter4/app/Controllers/Home.php:10:
object(CodeIgniter\HTTP\URI)[13]
  protected 'uriString' => null
  private ?string 'baseURL' => string 'http://localhost:8080/' (length=22)
  protected 'segments' => 
    array (size=0)
      empty
  protected 'scheme' => string 'http' (length=4)
  protected 'user' => null
  protected 'password' => null
  protected 'host' => string 'localhost' (length=9)
  protected 'port' => int 8080
  protected 'path' => string '/' (length=1)
  protected 'fragment' => string '' (length=0)
  protected 'query' => 
    array (size=0)
      empty
  protected 'defaultPorts' => 
    array (size=4)
      'http' => int 80
      'https' => int 443
      'ftp' => int 21
      'sftp' => int 22
  protected 'showPassword' => boolean false
  protected 'silent' => boolean false
  protected 'rawQueryString' => boolean false

/Users/kenji/work/codeigniter/official/CodeIgniter4/app/Controllers/Home.php:13:
object(CodeIgniter\HTTP\URI)[61]
  protected 'uriString' => null
  private ?string 'baseURL' => null
  protected 'segments' => 
    array (size=1)
      0 => string 'index.php' (length=9)
  protected 'scheme' => string 'http' (length=4)
  protected 'user' => null
  protected 'password' => null
  protected 'host' => string 'localhost' (length=9)
  protected 'port' => int 8080
  protected 'path' => string '/index.php/' (length=11)
  protected 'fragment' => string '' (length=0)
  protected 'query' => 
    array (size=0)
      empty
  protected 'defaultPorts' => 
    array (size=4)
      'http' => int 80
      'https' => int 443
      'ftp' => int 21
      'sftp' => int 22
  protected 'showPassword' => boolean false
  protected 'silent' => boolean false
  protected 'rawQueryString' => boolean false

2. baseURL with subfolder

From: #7123 (comment)

baseURL: http://localhost:8888/ci432/public/null
segments: []['ci432', 'public', 'index.php']
path: /'/ci432/public/index.php/'

Details
/Applications/MAMP/htdocs/ci432/app/Controllers/Home.php:10:
object(CodeIgniter\HTTP\URI)[12]
  protected 'uriString' => null
  private ?string 'baseURL' => string 'http://localhost:8080/' (length=22)
  protected 'segments' => 
    array (size=0)
      empty
  protected 'scheme' => string 'http' (length=4)
  protected 'user' => null
  protected 'password' => null
  protected 'host' => string 'localhost' (length=9)
  protected 'port' => int 8080
  protected 'path' => string '/' (length=1)
  protected 'fragment' => string '' (length=0)
  protected 'query' => 
    array (size=0)
      empty
  protected 'defaultPorts' => 
    array (size=4)
      'http' => int 80
      'https' => int 443
      'ftp' => int 21
      'sftp' => int 22
  protected 'showPassword' => boolean false
  protected 'silent' => boolean false
  protected 'rawQueryString' => boolean false

/Applications/MAMP/htdocs/ci432/app/Controllers/Home.php:13:
object(CodeIgniter\HTTP\URI)[51]
  protected 'uriString' => null
  private ?string 'baseURL' => null
  protected 'segments' => 
    array (size=1)
      0 => string 'index.php' (length=9)
  protected 'scheme' => string 'http' (length=4)
  protected 'user' => null
  protected 'password' => null
  protected 'host' => string 'localhost' (length=9)
  protected 'port' => int 8080
  protected 'path' => string '/index.php/' (length=11)
  protected 'fragment' => string '' (length=0)
  protected 'query' => 
    array (size=0)
      empty
  protected 'defaultPorts' => 
    array (size=4)
      'http' => int 80
      'https' => int 443
      'ftp' => int 21
      'sftp' => int 22
  protected 'showPassword' => boolean false
  protected 'silent' => boolean false
  protected 'rawQueryString' => boolean false

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugVerified issues on the current code behavior or pull requests that will fix them

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions