GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • codeigniter4/CodeIgniter4
  • Home
  • Welcome to CodeIgniter4
  • Server Requirements
  • Credits
  • PSR Compliance
  • License Agreement
  • Installation
  • Composer Installation
  • Manual Installation
  • Running Your App
  • Worker Mode
  • Troubleshooting
  • Deployment

This view

  • Original page
  • New address

GeezerVison is showing codeigniter4.github.io — CLIRequest Class - CodeIgniter

Edit this page

CLIRequest Class¶

If a request comes from a command line invocation, the request object is actually a CLIRequest. It behaves the same as a conventional request but adds some accessor methods for convenience.

Additional Accessors¶

getSegments()¶

Returns an array of the command line arguments deemed to be part of a path:

<?php

// command line: php index.php users 21 profile --foo bar
echo $request->getSegments();  // ['users', '21', 'profile']

getPath()¶

Returns the reconstructed path as a string:

<?php

// command line: php index.php users 21 profile --foo bar
echo $request->getPath();  // users/21/profile

getOptions()¶

Returns an array of the command line arguments deemed to be options:

<?php

// command line: php index.php users 21 profile --foo bar
echo $request->getOptions();  // ['foo' => 'bar']

getOption($key)¶

Returns the value of a specific command line argument deemed to be an option:

<?php

// command line: php index.php users 21 profile --foo bar
echo $request->getOption('foo');      // bar
echo $request->getOption('notthere'); // null

getOptionString()¶

Returns the reconstructed command line string for the options:

<?php

// command line: php index.php users 21 profile --foo bar
echo $request->getOptionString();  // -foo bar

Passing true to the first argument will try to write long options using two dashes:

<?php

// php index.php user 21 --foo bar -f
echo $request->getOptionString();     // -foo bar -f
echo $request->getOptionString(true); // --foo bar -f
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.