mirror of
https://github.com/codeigniter4/CodeIgniter4.git
synced 2025-02-20 11:44:28 +08:00
698 lines
49 KiB
HTML
698 lines
49 KiB
HTML
|
||
|
||
<!DOCTYPE html>
|
||
<html class="writer-html5" lang="en" >
|
||
<head>
|
||
<meta charset="utf-8" />
|
||
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||
|
||
<title>Working with URIs — CodeIgniter 4.1.1 documentation</title>
|
||
|
||
|
||
|
||
<link rel="stylesheet" href="../_static/css/citheme.css" type="text/css" />
|
||
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
|
||
|
||
|
||
|
||
<link rel="shortcut icon" href="../_static/favicon.ico"/>
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
<!--[if lt IE 9]>
|
||
<script src="../_static/js/html5shiv.min.js"></script>
|
||
<![endif]-->
|
||
|
||
|
||
<script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
|
||
<script src="../_static/jquery.js"></script>
|
||
<script src="../_static/underscore.js"></script>
|
||
<script src="../_static/doctools.js"></script>
|
||
<script src="../_static/language_data.js"></script>
|
||
<script src="../_static/js/citheme.js"></script>
|
||
<script src="../_static/js/carbon.js"></script>
|
||
|
||
<script type="text/javascript" src="../_static/js/theme.js"></script>
|
||
|
||
|
||
<link rel="index" title="Index" href="../genindex.html" />
|
||
<link rel="search" title="Search" href="../search.html" />
|
||
<link rel="next" title="User Agent Class" href="user_agent.html" />
|
||
<link rel="prev" title="Working with Uploaded Files" href="uploaded_files.html" />
|
||
</head>
|
||
|
||
<body class="wy-body-for-nav">
|
||
|
||
|
||
<div class="wy-grid-for-nav">
|
||
|
||
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
|
||
<div class="wy-side-scroll">
|
||
<div class="wy-side-nav-search" style="background: #DD4814" >
|
||
|
||
|
||
|
||
<a href="../index.html">
|
||
|
||
|
||
|
||
|
||
<img src="../_static/ci-logo-text.png" class="logo" alt="Logo"/>
|
||
|
||
</a>
|
||
|
||
|
||
|
||
|
||
<div role="search">
|
||
<form id="rtd-search-form" class="wy-form" action="../search.html" method="get">
|
||
<input type="text" name="q" placeholder="Search docs" />
|
||
<input type="hidden" name="check_keywords" value="yes" />
|
||
<input type="hidden" name="area" value="default" />
|
||
</form>
|
||
</div>
|
||
|
||
|
||
</div>
|
||
|
||
|
||
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
|
||
|
||
|
||
|
||
|
||
|
||
|
||
<ul>
|
||
<li class="toctree-l1"><a class="reference internal" href="../intro/index.html">Welcome to CodeIgniter4</a><ul>
|
||
<li class="toctree-l2"><a class="reference internal" href="../intro/index.html">Welcome to CodeIgniter4</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="../intro/requirements.html">Server Requirements</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="../intro/credits.html">Credits</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="../intro/psr.html">PSR Compliance</a></li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
<ul>
|
||
<li class="toctree-l1"><a class="reference internal" href="../installation/index.html">Installation</a><ul>
|
||
<li class="toctree-l2"><a class="reference internal" href="../installation/installing_composer.html">Composer Installation</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="../installation/installing_manual.html">Manual Installation</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="../installation/running.html">Running Your App</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="../installation/upgrading.html">Upgrading From a Previous Version</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="../installation/troubleshooting.html">Troubleshooting</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="../installation/repositories.html">CodeIgniter Repositories</a></li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
<ul>
|
||
<li class="toctree-l1"><a class="reference internal" href="../tutorial/index.html">Build Your First Application</a><ul>
|
||
<li class="toctree-l2"><a class="reference internal" href="../tutorial/static_pages.html">Static pages</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="../tutorial/news_section.html">News section</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="../tutorial/create_news_items.html">Create news items</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="../tutorial/conclusion.html">Conclusion</a></li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
<ul>
|
||
<li class="toctree-l1"><a class="reference internal" href="../concepts/index.html">CodeIgniter4 Overview</a><ul>
|
||
<li class="toctree-l2"><a class="reference internal" href="../concepts/structure.html">Application Structure</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="../concepts/mvc.html">Models, Views, and Controllers</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="../concepts/autoloader.html">Autoloading Files</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="../concepts/services.html">Services</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="../concepts/factories.html">Factories</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="../concepts/http.html">Working With HTTP Requests</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="../concepts/security.html">Security Guidelines</a></li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
<ul>
|
||
<li class="toctree-l1"><a class="reference internal" href="../general/index.html">General Topics</a><ul>
|
||
<li class="toctree-l2"><a class="reference internal" href="../general/configuration.html">Configuration</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="../general/urls.html">CodeIgniter URLs</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="../general/helpers.html">Helper Functions</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="../general/common_functions.html">Global Functions and Constants</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="../general/logging.html">Logging Information</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="../general/errors.html">Error Handling</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="../general/caching.html">Web Page Caching</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="../general/ajax.html">AJAX Requests</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="../general/modules.html">Code Modules</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="../general/managing_apps.html">Managing your Applications</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="../general/environments.html">Handling Multiple Environments</a></li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
<ul>
|
||
<li class="toctree-l1"><a class="reference internal" href="../incoming/index.html">Controllers and Routing</a><ul>
|
||
<li class="toctree-l2"><a class="reference internal" href="../incoming/controllers.html">Controllers</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="../incoming/routing.html">URI Routing</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="../incoming/filters.html">Controller Filters</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="../incoming/message.html">HTTP Messages</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="../incoming/request.html">Request Class</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="../incoming/incomingrequest.html">IncomingRequest Class</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="../incoming/content_negotiation.html">Content Negotiation</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="../incoming/methodspoofing.html">HTTP Method Spoofing</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="../incoming/restful.html">RESTful Resource Handling</a></li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
<ul>
|
||
<li class="toctree-l1"><a class="reference internal" href="../outgoing/index.html">Building Responses</a><ul>
|
||
<li class="toctree-l2"><a class="reference internal" href="../outgoing/views.html">Views</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="../outgoing/view_cells.html">View Cells</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="../outgoing/view_renderer.html">View Renderer</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="../outgoing/view_layouts.html">View Layouts</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="../outgoing/view_parser.html">View Parser</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="../outgoing/table.html">HTML Table Class</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="../outgoing/response.html">HTTP Responses</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="../outgoing/api_responses.html">API Response Trait</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="../outgoing/localization.html">Localization</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="../outgoing/alternative_php.html">Alternate PHP Syntax for View Files</a></li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
<ul>
|
||
<li class="toctree-l1"><a class="reference internal" href="../database/index.html">Working With Databases</a><ul>
|
||
<li class="toctree-l2"><a class="reference internal" href="../database/examples.html">Quick Start: Usage Examples</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="../database/configuration.html">Database Configuration</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="../database/connecting.html">Connecting to a Database</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="../database/queries.html">Running Queries</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="../database/results.html">Generating Query Results</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="../database/helpers.html">Query Helper Functions</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="../database/query_builder.html">Query Builder Class</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="../database/transactions.html">Transactions</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="../database/metadata.html">Getting MetaData</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="../database/call_function.html">Custom Function Calls</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="../database/events.html">Database Events</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="../database/utilities.html">Database Utilities</a></li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
<ul>
|
||
<li class="toctree-l1"><a class="reference internal" href="../models/index.html">Modeling Data</a><ul>
|
||
<li class="toctree-l2"><a class="reference internal" href="../models/model.html">Using CodeIgniter's Model</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="../models/entities.html">Using Entity Classes</a></li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
<ul>
|
||
<li class="toctree-l1"><a class="reference internal" href="../dbmgmt/index.html">Managing Databases</a><ul>
|
||
<li class="toctree-l2"><a class="reference internal" href="../dbmgmt/forge.html">Database Manipulation with Database Forge</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="../dbmgmt/migration.html">Database Migrations</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="../dbmgmt/seeds.html">Database Seeding</a></li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
<ul class="current">
|
||
<li class="toctree-l1 current"><a class="reference internal" href="index.html">Library Reference</a><ul class="current">
|
||
<li class="toctree-l2"><a class="reference internal" href="caching.html">Caching Driver</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="cookies.html">Cookies</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="curlrequest.html">CURLRequest Class</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="email.html">Email Class</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="encryption.html">Encryption Service</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="files.html">Working with Files</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="honeypot.html">Honeypot Class</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="images.html">Image Manipulation Class</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="pagination.html">Pagination</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="security.html">Security</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="sessions.html">Session Library</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="throttler.html">Throttler</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="time.html">Times and Dates</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="typography.html">Typography</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="uploaded_files.html">Working with Uploaded Files</a></li>
|
||
<li class="toctree-l2 current"><a class="current reference internal" href="#">Working with URIs</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="user_agent.html">User Agent Class</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="validation.html">Validation</a></li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
<ul>
|
||
<li class="toctree-l1"><a class="reference internal" href="../helpers/index.html">Helpers</a><ul>
|
||
<li class="toctree-l2"><a class="reference internal" href="../helpers/array_helper.html">Array Helper</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="../helpers/cookie_helper.html">Cookie Helper</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="../helpers/date_helper.html">Date Helper</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="../helpers/filesystem_helper.html">Filesystem Helper</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="../helpers/form_helper.html">Form Helper</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="../helpers/html_helper.html">HTML Helper</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="../helpers/inflector_helper.html">Inflector Helper</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="../helpers/number_helper.html">Number Helper</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="../helpers/security_helper.html">Security Helper</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="../helpers/test_helper.html">Test Helper</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="../helpers/text_helper.html">Text Helper</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="../helpers/url_helper.html">URL Helper</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="../helpers/xml_helper.html">XML Helper</a></li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
<ul>
|
||
<li class="toctree-l1"><a class="reference internal" href="../testing/index.html">Testing</a><ul>
|
||
<li class="toctree-l2"><a class="reference internal" href="../testing/overview.html">Getting Started</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="../testing/database.html">Database</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="../testing/fabricator.html">Generating Data</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="../testing/controllers.html">Controller Testing</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="../testing/feature.html">HTTP Testing</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="../testing/response.html">Testing Responses</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="../testing/benchmark.html">Benchmarking</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="../testing/debugging.html">Debugging Your Application</a></li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
<ul>
|
||
<li class="toctree-l1"><a class="reference internal" href="../cli/index.html">Command Line Usage</a><ul>
|
||
<li class="toctree-l2"><a class="reference internal" href="../cli/cli.html">Running via the Command Line</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="../cli/cli_commands.html">Custom CLI Commands</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="../cli/cli_generators.html">CLI Generators</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="../cli/cli_library.html">CLI Library</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="../cli/cli_request.html">CLIRequest Class</a></li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
<ul>
|
||
<li class="toctree-l1"><a class="reference internal" href="../extending/index.html">Extending CodeIgniter</a><ul>
|
||
<li class="toctree-l2"><a class="reference internal" href="../extending/core_classes.html">Creating Core System Classes</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="../extending/common.html">Replacing Common Functions</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="../extending/events.html">Events</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="../extending/basecontroller.html">Extending the Controller</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="../extending/authentication.html">Authentication</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="../extending/contributing.html">Contributing to CodeIgniter</a></li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
|
||
|
||
|
||
</div>
|
||
|
||
</div>
|
||
</nav>
|
||
|
||
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
|
||
|
||
|
||
<nav class="wy-nav-top" aria-label="top navigation">
|
||
|
||
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
|
||
<a href="../index.html">CodeIgniter</a>
|
||
|
||
</nav>
|
||
|
||
|
||
<div class="wy-nav-content">
|
||
|
||
<div class="rst-content">
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
<div role="navigation" aria-label="breadcrumbs navigation">
|
||
|
||
<ul class="wy-breadcrumbs">
|
||
|
||
<li><a href="../index.html" class="icon icon-home"></a> »</li>
|
||
|
||
<li><a href="index.html">Library Reference</a> »</li>
|
||
|
||
<li>Working with URIs</li>
|
||
|
||
|
||
<li class="wy-breadcrumbs-aside">
|
||
|
||
|
||
|
||
</li>
|
||
|
||
</ul>
|
||
|
||
|
||
<hr/>
|
||
</div>
|
||
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
|
||
<div itemprop="articleBody">
|
||
|
||
<div class="section" id="working-with-uris">
|
||
<h1>Working with URIs<a class="headerlink" href="#working-with-uris" title="Permalink to this headline">¶</a></h1>
|
||
<p>CodeIgniter provides an object oriented solution for working with URI’s in your application. Using this makes it
|
||
simple to ensure that the structure is always correct, no matter how complex the URI might be, as well as adding
|
||
relative URI to an existing one and have it resolved safely and correctly.</p>
|
||
<div class="contents local topic" id="contents">
|
||
<ul class="simple">
|
||
<li><p><a class="reference internal" href="#creating-uri-instances" id="id1">Creating URI instances</a></p>
|
||
<ul>
|
||
<li><p><a class="reference internal" href="#the-current-uri" id="id2">The Current URI</a></p></li>
|
||
</ul>
|
||
</li>
|
||
<li><p><a class="reference internal" href="#uri-strings" id="id3">URI Strings</a></p></li>
|
||
<li><p><a class="reference internal" href="#the-uri-parts" id="id4">The URI Parts</a></p>
|
||
<ul>
|
||
<li><p><a class="reference internal" href="#scheme" id="id5">Scheme</a></p></li>
|
||
<li><p><a class="reference internal" href="#authority" id="id6">Authority</a></p></li>
|
||
<li><p><a class="reference internal" href="#userinfo" id="id7">Userinfo</a></p></li>
|
||
<li><p><a class="reference internal" href="#host" id="id8">Host</a></p></li>
|
||
<li><p><a class="reference internal" href="#port" id="id9">Port</a></p></li>
|
||
<li><p><a class="reference internal" href="#path" id="id10">Path</a></p></li>
|
||
<li><p><a class="reference internal" href="#query" id="id11">Query</a></p></li>
|
||
<li><p><a class="reference internal" href="#fragment" id="id12">Fragment</a></p></li>
|
||
</ul>
|
||
</li>
|
||
<li><p><a class="reference internal" href="#uri-segments" id="id13">URI Segments</a></p></li>
|
||
<li><p><a class="reference internal" href="#disable-throwing-exceptions" id="id14">Disable Throwing Exceptions</a></p></li>
|
||
</ul>
|
||
</div>
|
||
<div class="section" id="creating-uri-instances">
|
||
<h2><a class="toc-backref" href="#id1">Creating URI instances</a><a class="headerlink" href="#creating-uri-instances" title="Permalink to this headline">¶</a></h2>
|
||
<p>Creating a URI instance is as simple as creating a new class instance:</p>
|
||
<div class="highlight-html+php notranslate"><div class="highlight"><pre><span></span><span class="nv">$uri</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">\CodeIgniter\HTTP\URI</span><span class="p">();</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>Alternatively, you can use the <code class="docutils literal notranslate"><span class="pre">service()</span></code> function to return an instance for you:</p>
|
||
<div class="highlight-html+php notranslate"><div class="highlight"><pre><span></span><span class="nv">$uri</span> <span class="o">=</span> <span class="nx">service</span><span class="p">(</span><span class="s1">'uri'</span><span class="p">);</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>When you create the new instance, you can pass a full or partial URL in the constructor and it will be parsed
|
||
into its appropriate sections:</p>
|
||
<div class="highlight-html+php notranslate"><div class="highlight"><pre><span></span><span class="nv">$uri</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">\CodeIgniter\HTTP\URI</span><span class="p">(</span><span class="s1">'http://www.example.com/some/path'</span><span class="p">);</span>
|
||
<span class="nv">$uri</span> <span class="o">=</span> <span class="nx">service</span><span class="p">(</span><span class="s1">'uri'</span><span class="p">,</span> <span class="s1">'http://www.example.com/some/path'</span><span class="p">);</span>
|
||
</pre></div>
|
||
</div>
|
||
<div class="section" id="the-current-uri">
|
||
<h3><a class="toc-backref" href="#id2">The Current URI</a><a class="headerlink" href="#the-current-uri" title="Permalink to this headline">¶</a></h3>
|
||
<p>Many times, all you really want is an object representing the current URL of this request.
|
||
You can use one of the functions available in the <strong>url_helper</strong>:</p>
|
||
<div class="highlight-html+php notranslate"><div class="highlight"><pre><span></span><span class="nv">$uri</span> <span class="o">=</span> <span class="nx">current_url</span><span class="p">(</span><span class="k">true</span><span class="p">);</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>You must pass <code class="docutils literal notranslate"><span class="pre">true</span></code> as the first parameter, otherwise, it will return the string representation of the current URL.
|
||
This URI is based on the path (relative to your <code class="docutils literal notranslate"><span class="pre">baseURL</span></code>) as determined by the current request object and
|
||
your settings in <code class="docutils literal notranslate"><span class="pre">Config\App</span></code> (baseURL, indexPage, and forceGlobalSecureRequests).
|
||
Assuming that you’re in a controller that extends <code class="docutils literal notranslate"><span class="pre">CodeIgniter\Controller</span></code> you can get this relative path:</p>
|
||
<div class="highlight-html+php notranslate"><div class="highlight"><pre><span></span><span class="nv">$path</span> <span class="o">=</span> <span class="nv">$this</span><span class="o">-></span><span class="na">request</span><span class="o">-></span><span class="na">getPath</span><span class="p">();</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="uri-strings">
|
||
<h2><a class="toc-backref" href="#id3">URI Strings</a><a class="headerlink" href="#uri-strings" title="Permalink to this headline">¶</a></h2>
|
||
<p>Many times, all you really want is to get a string representation of a URI. This is easy to do by simply casting
|
||
the URI as a string:</p>
|
||
<div class="highlight-html+php notranslate"><div class="highlight"><pre><span></span><span class="nv">$uri</span> <span class="o">=</span> <span class="nx">current_url</span><span class="p">(</span><span class="k">true</span><span class="p">);</span>
|
||
<span class="k">echo</span> <span class="p">(</span><span class="nx">string</span><span class="p">)</span> <span class="nv">$uri</span><span class="p">;</span> <span class="c1">// http://example.com/index.php</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>If you know the pieces of the URI and just want to ensure it’s all formatted correctly, you can generate a string
|
||
using the URI class’ static <code class="docutils literal notranslate"><span class="pre">createURIString()</span></code> method:</p>
|
||
<div class="highlight-html+php notranslate"><div class="highlight"><pre><span></span><span class="nv">$uriString</span> <span class="o">=</span> <span class="nx">URI</span><span class="o">::</span><span class="na">createURIString</span><span class="p">(</span><span class="nv">$scheme</span><span class="p">,</span> <span class="nv">$authority</span><span class="p">,</span> <span class="nv">$path</span><span class="p">,</span> <span class="nv">$query</span><span class="p">,</span> <span class="nv">$fragment</span><span class="p">);</span>
|
||
|
||
<span class="c1">// Creates: http://exmample.com/some/path?foo=bar#first-heading</span>
|
||
<span class="k">echo</span> <span class="nx">URI</span><span class="o">::</span><span class="na">createURIString</span><span class="p">(</span><span class="s1">'http'</span><span class="p">,</span> <span class="s1">'example.com'</span><span class="p">,</span> <span class="s1">'some/path'</span><span class="p">,</span> <span class="s1">'foo=bar'</span><span class="p">,</span> <span class="s1">'first-heading'</span><span class="p">);</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="the-uri-parts">
|
||
<h2><a class="toc-backref" href="#id4">The URI Parts</a><a class="headerlink" href="#the-uri-parts" title="Permalink to this headline">¶</a></h2>
|
||
<p>Once you have a URI instance, you can set or retrieve any of the various parts of the URI. This section will provide
|
||
details on what those parts are, and how to work with them.</p>
|
||
<div class="section" id="scheme">
|
||
<h3><a class="toc-backref" href="#id5">Scheme</a><a class="headerlink" href="#scheme" title="Permalink to this headline">¶</a></h3>
|
||
<p>The scheme is frequently ‘http’ or ‘https’, but any scheme is supported, including ‘file’, ‘mailto’, etc.</p>
|
||
<div class="highlight-html+php notranslate"><div class="highlight"><pre><span></span><span class="nv">$uri</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">\CodeIgniter\HTTP\URI</span><span class="p">(</span><span class="s1">'http://www.example.com/some/path'</span><span class="p">);</span>
|
||
|
||
<span class="k">echo</span> <span class="nv">$uri</span><span class="o">-></span><span class="na">getScheme</span><span class="p">();</span> <span class="c1">// 'http'</span>
|
||
<span class="nv">$uri</span><span class="o">-></span><span class="na">setScheme</span><span class="p">(</span><span class="s1">'https'</span><span class="p">);</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="authority">
|
||
<h3><a class="toc-backref" href="#id6">Authority</a><a class="headerlink" href="#authority" title="Permalink to this headline">¶</a></h3>
|
||
<p>Many URIs contain several elements that are collectively known as the ‘authority’. This includes any user info,
|
||
the host and the port number. You can retrieve all of these pieces as one single string with the <code class="docutils literal notranslate"><span class="pre">getAuthority()</span></code>
|
||
method, or you can manipulate the individual parts.</p>
|
||
<div class="highlight-html+php notranslate"><div class="highlight"><pre><span></span><span class="nv">$uri</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">\CodeIgniter\HTTP\URI</span><span class="p">(</span><span class="s1">'ftp://user:password@example.com:21/some/path'</span><span class="p">);</span>
|
||
|
||
<span class="k">echo</span> <span class="nv">$uri</span><span class="o">-></span><span class="na">getAuthority</span><span class="p">();</span> <span class="c1">// user@example.com:21</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>By default, this will not display the password portion since you wouldn’t want to show that to anyone. If you want
|
||
to show the password, you can use the <code class="docutils literal notranslate"><span class="pre">showPassword()</span></code> method. This URI instance will continue to show that password
|
||
until you turn it off again, so always make sure that you turn it off as soon as you are finished with it:</p>
|
||
<div class="highlight-html+php notranslate"><div class="highlight"><pre><span></span><span class="k">echo</span> <span class="nv">$uri</span><span class="o">-></span><span class="na">getAuthority</span><span class="p">();</span> <span class="c1">// user@example.com:21</span>
|
||
<span class="k">echo</span> <span class="nv">$uri</span><span class="o">-></span><span class="na">showPassword</span><span class="p">()</span><span class="o">-></span><span class="na">getAuthority</span><span class="p">();</span> <span class="c1">// user:password@example.com:21</span>
|
||
|
||
<span class="c1">// Turn password display off again.</span>
|
||
<span class="nv">$uri</span><span class="o">-></span><span class="na">showPassword</span><span class="p">(</span><span class="k">false</span><span class="p">);</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>If you do not want to display the port, pass in <code class="docutils literal notranslate"><span class="pre">true</span></code> as the only parameter:</p>
|
||
<div class="highlight-html+php notranslate"><div class="highlight"><pre><span></span><span class="k">echo</span> <span class="nv">$uri</span><span class="o">-></span><span class="na">getAuthority</span><span class="p">(</span><span class="k">true</span><span class="p">);</span> <span class="c1">// user@example.com</span>
|
||
</pre></div>
|
||
</div>
|
||
<div class="admonition note">
|
||
<p class="admonition-title">Note</p>
|
||
<p>If the current port is the default port for the scheme it will never be displayed.</p>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="userinfo">
|
||
<h3><a class="toc-backref" href="#id7">Userinfo</a><a class="headerlink" href="#userinfo" title="Permalink to this headline">¶</a></h3>
|
||
<p>The userinfo section is simply the username and password that you might see with an FTP URI. While you can get
|
||
this as part of the Authority, you can also retrieve it yourself:</p>
|
||
<div class="highlight-html+php notranslate"><div class="highlight"><pre><span></span><span class="k">echo</span> <span class="nv">$uri</span><span class="o">-></span><span class="na">getUserInfo</span><span class="p">();</span> <span class="c1">// user</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>By default, it will not display the password, but you can override that with the <code class="docutils literal notranslate"><span class="pre">showPassword()</span></code> method:</p>
|
||
<div class="highlight-html+php notranslate"><div class="highlight"><pre><span></span><span class="k">echo</span> <span class="nv">$uri</span><span class="o">-></span><span class="na">showPassword</span><span class="p">()</span><span class="o">-></span><span class="na">getUserInfo</span><span class="p">();</span> <span class="c1">// user:password</span>
|
||
<span class="nv">$uri</span><span class="o">-></span><span class="na">showPassword</span><span class="p">(</span><span class="k">false</span><span class="p">);</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="host">
|
||
<h3><a class="toc-backref" href="#id8">Host</a><a class="headerlink" href="#host" title="Permalink to this headline">¶</a></h3>
|
||
<p>The host portion of the URI is typically the domain name of the URL. This can be easily set and retrieved with the
|
||
<code class="docutils literal notranslate"><span class="pre">getHost()</span></code> and <code class="docutils literal notranslate"><span class="pre">setHost()</span></code> methods:</p>
|
||
<div class="highlight-html+php notranslate"><div class="highlight"><pre><span></span><span class="nv">$uri</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">\CodeIgniter\HTTP\URI</span><span class="p">(</span><span class="s1">'http://www.example.com/some/path'</span><span class="p">);</span>
|
||
|
||
<span class="k">echo</span> <span class="nv">$uri</span><span class="o">-></span><span class="na">getHost</span><span class="p">();</span> <span class="c1">// www.example.com</span>
|
||
<span class="k">echo</span> <span class="nv">$uri</span><span class="o">-></span><span class="na">setHost</span><span class="p">(</span><span class="s1">'anotherexample.com'</span><span class="p">)</span><span class="o">-></span><span class="na">getHost</span><span class="p">();</span> <span class="c1">// anotherexample.com</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="port">
|
||
<h3><a class="toc-backref" href="#id9">Port</a><a class="headerlink" href="#port" title="Permalink to this headline">¶</a></h3>
|
||
<p>The port is an integer number between 0 and 65535. Each sheme has a default value associated with it.</p>
|
||
<div class="highlight-html+php notranslate"><div class="highlight"><pre><span></span><span class="nv">$uri</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">\CodeIgniter\HTTP\URI</span><span class="p">(</span><span class="s1">'ftp://user:password@example.com:21/some/path'</span><span class="p">);</span>
|
||
|
||
<span class="k">echo</span> <span class="nv">$uri</span><span class="o">-></span><span class="na">getPort</span><span class="p">();</span> <span class="c1">// 21</span>
|
||
<span class="k">echo</span> <span class="nv">$uri</span><span class="o">-></span><span class="na">setPort</span><span class="p">(</span><span class="mi">2201</span><span class="p">)</span><span class="o">-></span><span class="na">getPort</span><span class="p">();</span> <span class="c1">// 2201</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>When using the <code class="docutils literal notranslate"><span class="pre">setPort()</span></code> method, the port will be checked that it is within the valid range and assigned.</p>
|
||
</div>
|
||
<div class="section" id="path">
|
||
<h3><a class="toc-backref" href="#id10">Path</a><a class="headerlink" href="#path" title="Permalink to this headline">¶</a></h3>
|
||
<p>The path are all of the segments within the site itself. As expected, the <code class="docutils literal notranslate"><span class="pre">getPath()</span></code> and <code class="docutils literal notranslate"><span class="pre">setPath()</span></code> methods
|
||
can be used to manipulate it:</p>
|
||
<div class="highlight-html+php notranslate"><div class="highlight"><pre><span></span><span class="nv">$uri</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">\CodeIgniter\HTTP\URI</span><span class="p">(</span><span class="s1">'http://www.example.com/some/path'</span><span class="p">);</span>
|
||
|
||
<span class="k">echo</span> <span class="nv">$uri</span><span class="o">-></span><span class="na">getPath</span><span class="p">();</span> <span class="c1">// 'some/path'</span>
|
||
<span class="k">echo</span> <span class="nv">$uri</span><span class="o">-></span><span class="na">setPath</span><span class="p">(</span><span class="s1">'another/path'</span><span class="p">)</span><span class="o">-></span><span class="na">getPath</span><span class="p">();</span> <span class="c1">// 'another/path'</span>
|
||
</pre></div>
|
||
</div>
|
||
<div class="admonition note">
|
||
<p class="admonition-title">Note</p>
|
||
<p>When setting the path this way, or any other way the class allows, it is sanitized to encode any dangerous
|
||
characters, and remove dot segments for safety.</p>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="query">
|
||
<h3><a class="toc-backref" href="#id11">Query</a><a class="headerlink" href="#query" title="Permalink to this headline">¶</a></h3>
|
||
<p>The query variables can be manipulated through the class using simple string representations. Query values can only
|
||
be set as a string currently.</p>
|
||
<div class="highlight-html+php notranslate"><div class="highlight"><pre><span></span><span class="nv">$uri</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">\CodeIgniter\HTTP\URI</span><span class="p">(</span><span class="s1">'http://www.example.com?foo=bar'</span><span class="p">);</span>
|
||
|
||
<span class="k">echo</span> <span class="nv">$uri</span><span class="o">-></span><span class="na">getQuery</span><span class="p">();</span> <span class="c1">// 'foo=bar'</span>
|
||
<span class="nv">$uri</span><span class="o">-></span><span class="na">setQuery</span><span class="p">(</span><span class="s1">'foo=bar&bar=baz'</span><span class="p">);</span>
|
||
</pre></div>
|
||
</div>
|
||
<div class="admonition note">
|
||
<p class="admonition-title">Note</p>
|
||
<p>Query values cannot contain fragments. An InvalidArgumentException will be thrown if it does.</p>
|
||
</div>
|
||
<p>You can set query values using an array:</p>
|
||
<div class="highlight-html+php notranslate"><div class="highlight"><pre><span></span><span class="nv">$uri</span><span class="o">-></span><span class="na">setQueryArray</span><span class="p">([</span><span class="s1">'foo'</span> <span class="o">=></span> <span class="s1">'bar'</span><span class="p">,</span> <span class="s1">'bar'</span> <span class="o">=></span> <span class="s1">'baz'</span><span class="p">]);</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>The <code class="docutils literal notranslate"><span class="pre">setQuery()</span></code> and <code class="docutils literal notranslate"><span class="pre">setQueryArray()</span></code> methods overwrite any existing query variables. You can add a value to the
|
||
query variables collection without destroying the existing query variables with the <code class="docutils literal notranslate"><span class="pre">addQuery()</span></code> method. The first
|
||
parameter is the name of the variable, and the second parameter is the value:</p>
|
||
<div class="highlight-html+php notranslate"><div class="highlight"><pre><span></span><span class="nv">$uri</span><span class="o">-></span><span class="na">addQuery</span><span class="p">(</span><span class="s1">'foo'</span><span class="p">,</span> <span class="s1">'bar'</span><span class="p">);</span>
|
||
</pre></div>
|
||
</div>
|
||
<p><strong>Filtering Query Values</strong></p>
|
||
<p>You can filter the query values returned by passing an options array to the <code class="docutils literal notranslate"><span class="pre">getQuery()</span></code> method, with either an
|
||
<em>only</em> or an <em>except</em> key:</p>
|
||
<div class="highlight-html+php notranslate"><div class="highlight"><pre><span></span><span class="nv">$uri</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">\CodeIgniter\HTTP\URI</span><span class="p">(</span><span class="s1">'http://www.example.com?foo=bar&bar=baz&baz=foz'</span><span class="p">);</span>
|
||
|
||
<span class="c1">// Returns 'foo=bar'</span>
|
||
<span class="k">echo</span> <span class="nv">$uri</span><span class="o">-></span><span class="na">getQuery</span><span class="p">([</span><span class="s1">'only'</span> <span class="o">=></span> <span class="p">[</span><span class="s1">'foo'</span><span class="p">]);</span>
|
||
|
||
<span class="c1">// Returns 'foo=bar&baz=foz'</span>
|
||
<span class="k">echo</span> <span class="nv">$uri</span><span class="o">-></span><span class="na">getQuery</span><span class="p">([</span><span class="s1">'except'</span> <span class="o">=></span> <span class="p">[</span><span class="s1">'bar'</span><span class="p">]]);</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>This only changes the values returned during this one call. If you need to modify the URI’s query values more permanently,
|
||
you can use the <code class="docutils literal notranslate"><span class="pre">stripQuery()</span></code> and <code class="docutils literal notranslate"><span class="pre">keepQuery()</span></code> methods to change the actual object’s query variable collection:</p>
|
||
<div class="highlight-html+php notranslate"><div class="highlight"><pre><span></span><span class="nv">$uri</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">\CodeIgniter\HTTP\URI</span><span class="p">(</span><span class="s1">'http://www.example.com?foo=bar&bar=baz&baz=foz'</span><span class="p">);</span>
|
||
|
||
<span class="c1">// Leaves just the 'baz' variable</span>
|
||
<span class="nv">$uri</span><span class="o">-></span><span class="na">stripQuery</span><span class="p">(</span><span class="s1">'foo'</span><span class="p">,</span> <span class="s1">'bar'</span><span class="p">);</span>
|
||
|
||
<span class="c1">// Leaves just the 'foo' variable</span>
|
||
<span class="nv">$uri</span><span class="o">-></span><span class="na">keepQuery</span><span class="p">(</span><span class="s1">'foo'</span><span class="p">);</span>
|
||
</pre></div>
|
||
</div>
|
||
<div class="admonition note">
|
||
<p class="admonition-title">Note</p>
|
||
<p>By default <code class="docutils literal notranslate"><span class="pre">setQuery()</span></code> and <code class="docutils literal notranslate"><span class="pre">setQueryArray()</span></code> methods uses native <code class="docutils literal notranslate"><span class="pre">parse_str()</span></code> function to prepare data.
|
||
If you want to use more liberal rules (which allow key names to contain dots), you can use a special method
|
||
<code class="docutils literal notranslate"><span class="pre">useRawQueryString()</span></code> beforehand.</p>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="fragment">
|
||
<h3><a class="toc-backref" href="#id12">Fragment</a><a class="headerlink" href="#fragment" title="Permalink to this headline">¶</a></h3>
|
||
<p>Fragments are the portion at the end of the URL, preceded by the pound-sign (#). In HTML URL’s these are links
|
||
to an on-page anchor. Media URI’s can make use of them in various other ways.</p>
|
||
<div class="highlight-html+php notranslate"><div class="highlight"><pre><span></span><span class="nv">$uri</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">\CodeIgniter\HTTP\URI</span><span class="p">(</span><span class="s1">'http://www.example.com/some/path#first-heading'</span><span class="p">);</span>
|
||
|
||
<span class="k">echo</span> <span class="nv">$uri</span><span class="o">-></span><span class="na">getFragment</span><span class="p">();</span> <span class="c1">// 'first-heading'</span>
|
||
<span class="k">echo</span> <span class="nv">$uri</span><span class="o">-></span><span class="na">setFragment</span><span class="p">(</span><span class="s1">'second-heading'</span><span class="p">)</span><span class="o">-></span><span class="na">getFragment</span><span class="p">();</span> <span class="c1">// 'second-heading'</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="uri-segments">
|
||
<h2><a class="toc-backref" href="#id13">URI Segments</a><a class="headerlink" href="#uri-segments" title="Permalink to this headline">¶</a></h2>
|
||
<p>Each section of the path between the slashes is a single segment. The URI class provides a simple way to determine
|
||
what the values of the segments are. The segments start at 1 being the furthest left of the path.</p>
|
||
<div class="highlight-html+php notranslate"><div class="highlight"><pre><span></span><span class="c1">// URI = http://example.com/users/15/profile</span>
|
||
|
||
<span class="c1">// Prints '15'</span>
|
||
<span class="k">if</span> <span class="p">(</span><span class="nv">$uri</span><span class="o">-></span><span class="na">getSegment</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span> <span class="o">==</span> <span class="s1">'users'</span><span class="p">)</span>
|
||
<span class="p">{</span>
|
||
<span class="k">echo</span> <span class="nv">$uri</span><span class="o">-></span><span class="na">getSegment</span><span class="p">(</span><span class="mi">2</span><span class="p">);</span>
|
||
<span class="p">}</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>You can also set a different default value for a particular segment by using the second parameter of the <code class="docutils literal notranslate"><span class="pre">getSegment()</span></code> method. The default is empty string.</p>
|
||
<div class="highlight-html+php notranslate"><div class="highlight"><pre><span></span><span class="c1">// URI = http://example.com/users/15/profile</span>
|
||
|
||
<span class="c1">// will print 'profile'</span>
|
||
<span class="k">echo</span> <span class="nv">$uri</span><span class="o">-></span><span class="na">getSegment</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="s1">'foo'</span><span class="p">);</span>
|
||
<span class="c1">// will print 'bar'</span>
|
||
<span class="k">echo</span> <span class="nv">$uri</span><span class="o">-></span><span class="na">getSegment</span><span class="p">(</span><span class="mi">4</span><span class="p">,</span> <span class="s1">'bar'</span><span class="p">);</span>
|
||
<span class="c1">// will throw an exception</span>
|
||
<span class="k">echo</span> <span class="nv">$uri</span><span class="o">-></span><span class="na">getSegment</span><span class="p">(</span><span class="mi">5</span><span class="p">,</span> <span class="s1">'baz'</span><span class="p">);</span>
|
||
<span class="c1">// will print 'baz'</span>
|
||
<span class="k">echo</span> <span class="nv">$uri</span><span class="o">-></span><span class="na">setSilent</span><span class="p">()</span><span class="o">-></span><span class="na">getSegment</span><span class="p">(</span><span class="mi">5</span><span class="p">,</span> <span class="s1">'baz'</span><span class="p">);</span>
|
||
<span class="c1">// will print '' (empty string)</span>
|
||
<span class="k">echo</span> <span class="nv">$uri</span><span class="o">-></span><span class="na">setSilent</span><span class="p">()</span><span class="o">-></span><span class="na">getSegment</span><span class="p">(</span><span class="mi">5</span><span class="p">);</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>You can get a count of the total segments:</p>
|
||
<div class="highlight-html+php notranslate"><div class="highlight"><pre><span></span><span class="nv">$total</span> <span class="o">=</span> <span class="nv">$uri</span><span class="o">-></span><span class="na">getTotalSegments</span><span class="p">();</span> <span class="c1">// 3</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>Finally, you can retrieve an array of all of the segments:</p>
|
||
<div class="highlight-html+php notranslate"><div class="highlight"><pre><span></span><span class="nv">$segments</span> <span class="o">=</span> <span class="nv">$uri</span><span class="o">-></span><span class="na">getSegments</span><span class="p">();</span>
|
||
|
||
<span class="c1">// $segments =</span>
|
||
<span class="p">[</span>
|
||
<span class="mi">0</span> <span class="o">=></span> <span class="s1">'users'</span><span class="p">,</span>
|
||
<span class="mi">1</span> <span class="o">=></span> <span class="s1">'15'</span><span class="p">,</span>
|
||
<span class="mi">2</span> <span class="o">=></span> <span class="s1">'profile'</span>
|
||
<span class="p">]</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="disable-throwing-exceptions">
|
||
<h2><a class="toc-backref" href="#id14">Disable Throwing Exceptions</a><a class="headerlink" href="#disable-throwing-exceptions" title="Permalink to this headline">¶</a></h2>
|
||
<p>By default, some methods of this class may throw an exception. If you want to disable it, you can set a special flag
|
||
that will prevent throwing exceptions.</p>
|
||
<div class="highlight-html+php notranslate"><div class="highlight"><pre><span></span><span class="c1">// Disable throwing exceptions</span>
|
||
<span class="nv">$uri</span><span class="o">-></span><span class="na">setSilent</span><span class="p">();</span>
|
||
|
||
<span class="c1">// Enable throwing exceptions (default)</span>
|
||
<span class="nv">$uri</span><span class="o">-></span><span class="na">setSilent</span><span class="p">(</span><span class="k">false</span><span class="p">);</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
|
||
</div>
|
||
|
||
</div>
|
||
<footer>
|
||
<div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
|
||
<a href="user_agent.html" class="btn btn-neutral float-right" title="User Agent Class" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
|
||
<a href="uploaded_files.html" class="btn btn-neutral float-left" title="Working with Uploaded Files" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
|
||
</div>
|
||
|
||
<hr/>
|
||
|
||
<div role="contentinfo">
|
||
<p>
|
||
© Copyright 2019-2021 CodeIgniter Foundation.
|
||
<span class="lastupdated">
|
||
Last updated on May 16, 2021.
|
||
</span>
|
||
|
||
</p>
|
||
</div>
|
||
|
||
|
||
|
||
Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a
|
||
|
||
<a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a>
|
||
|
||
provided by <a href="https://readthedocs.org">Read the Docs</a>.
|
||
|
||
</footer>
|
||
</div>
|
||
</div>
|
||
|
||
</section>
|
||
|
||
</div>
|
||
|
||
|
||
<script type="text/javascript">
|
||
jQuery(function () {
|
||
SphinxRtdTheme.Navigation.enable(false);
|
||
});
|
||
</script>
|
||
|
||
|
||
|
||
|
||
|
||
|
||
</body>
|
||
</html> |