Skip to content

Conversation

@kenjis
Copy link
Member

@kenjis kenjis commented Feb 9, 2023

Description

  • add note for URI Segments

baseURL: http://localhost:8888/ci431/public/

<?php

namespace App\Controllers;

class Home extends BaseController
{
    public function index()
    {
        var_dump($this->request->getUri()->getSegments());
        var_dump($this->request->getUri()->getSegment(1));
    }
}

Navigate to http://localhost:8888/ci431/public/one/two/three

/Applications/MAMP/htdocs/ci431/app/Controllers/Home.php:9:
array (size=3)
  0 => string 'one' (length=3)
  1 => string 'two' (length=3)
  2 => string 'three' (length=5)

/Applications/MAMP/htdocs/ci431/app/Controllers/Home.php:10:string 'one' (length=3)

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value
  • [] Unit testing, with >80% coverage
  • User guide updated
  • [] Conforms to style guide

@kenjis kenjis added the documentation Pull requests for documentation only label Feb 9, 2023
@kenjis
Copy link
Member Author

kenjis commented Feb 11, 2023

I found the inconsistency between $this->request->getUri() and current_url(true).

<?php

namespace App\Controllers;

class Home extends BaseController
{
    public function index()
    {
        var_dump($this->request->getUri()->getSegments());
        var_dump($this->request->getUri()->getSegment(1));
        $uri = current_url(true);
        var_dump($uri->getSegments());
        var_dump($uri->getSegment(1));
    }
}
/Applications/MAMP/htdocs/ci431/app/Controllers/Home.php:9:
array (size=3)
  0 => string 'one' (length=3)
  1 => string 'two' (length=3)
  2 => string 'three' (length=5)

/Applications/MAMP/htdocs/ci431/app/Controllers/Home.php:10:string 'one' (length=3)

/Applications/MAMP/htdocs/ci431/app/Controllers/Home.php:12:
array (size=6)
  0 => string 'ci431' (length=5)
  1 => string 'public' (length=6)
  2 => string 'index.php' (length=9)
  3 => string 'one' (length=3)
  4 => string 'two' (length=3)
  5 => string 'three' (length=5)

/Applications/MAMP/htdocs/ci431/app/Controllers/Home.php:13:string 'ci431' (length=5)

@kenjis kenjis marked this pull request as draft February 11, 2023 23:40
@kenjis kenjis force-pushed the docs-add-note-uri.rst branch from 47d8e50 to 5f36dc5 Compare February 12, 2023 00:12
@kenjis kenjis marked this pull request as ready for review February 12, 2023 00:17
@kenjis kenjis marked this pull request as draft February 14, 2023 01:47
@kenjis kenjis force-pushed the docs-add-note-uri.rst branch from 5f36dc5 to 3c48531 Compare February 23, 2023 08:54
@kenjis kenjis marked this pull request as ready for review February 23, 2023 08:55
@kenjis
Copy link
Member Author

kenjis commented Feb 23, 2023

Improved the description.
I think ready to merge.

@kenjis kenjis merged commit f1caaee into codeigniter4:develop Feb 23, 2023
@kenjis kenjis deleted the docs-add-note-uri.rst branch February 23, 2023 23:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Pull requests for documentation only

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants