CLIRequest Class
If a request comes from a command line invocation, the request object is actually aCLIRequest
. It behaves the same as a conventional requestbut adds some accessor methods for convenience.
Additional Accessors
getSegments()
Returns an array of the command line arguments deemed to be part of a path:
- // command line: php index.php users 21 profile -foo bar
- echo $request->getSegments(); // ['users', '21', 'profile']
getPath()
Returns the reconstructed path as a string:
- // 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:
- // command line: php index.php users 21 profile -foo bar
- echo $request->getOptions(); // ['foo' => 'bar']
getOption($which)
Returns the value of a specific command line argument deemed to be an option:
- // 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:
- // command line: php index.php users 21 profile -foo bar
- echo $request->getOptionPath(); // -foo bar
当前内容版权归 codeigniter4 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 codeigniter4 .