CodeIgniter4 CLI Request Class

2020-08-17 17:56 更新

CLIRequest類(lèi)

如果請(qǐng)求來(lái)自命令行調(diào)用,則請(qǐng)求對(duì)象實(shí)際上是 CLIRequest。它的行為與常規(guī)請(qǐng)求相同, 但為方便起見(jiàn)添加了一些訪問(wèn)器方法。

其他訪問(wèn)器

getSegments()

返回被視為路徑一部分的命令行參數(shù)數(shù)組:

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

getPath()

以字符串形式返回重建的路徑:

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

getOptions()

返回被視為選項(xiàng)的命令行參數(shù)數(shù)組:

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

getOption($which)

返回被視為選項(xiàng)的特定命令行參數(shù)的值:

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

getOptionString()

返回選項(xiàng)的重構(gòu)的命令行字符串:

// command line: php index.php users 21 profile -foo bar
echo $request->getOptionPath();  // -foo bar
以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)