本文整理汇总了PHP中yii\helpers\Console::select方法的典型用法代码示例。如果您正苦于以下问题:PHP Console::select方法的具体用法?PHP Console::select怎么用?PHP Console::select使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\helpers\Console
的用法示例。
在下文中一共展示了Console::select方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: select
/**
* Gives the user an option to choose from. Giving '?' as an input will show
* a list of options to choose from and their explanations.
*
* @param string $prompt the prompt message
* @param array $options Key-value array of options to choose from
*
* @return string An option character the user chose
*/
public function select($prompt, $options = [])
{
return Console::select($prompt, $options);
}
示例2: actionCreate
/**
* Create a user.
*/
public function actionCreate()
{
$groups = Group::find()->disableAccessCheck()->orderBy('name')->all();
$this->out("Groups");
$options = [];
$i = 1;
$defaultGroup = null;
foreach ($groups as $group) {
$extra = '';
if ($group->system === 'users') {
$defaultGroup = $group->primaryKey;
$extra = '*';
}
$options[$i] = $group->primaryKey;
$this->out("{$i}) {$group->descriptor}{$extra}");
$i++;
}
$options[''] = $defaultGroup;
$group = Console::select("Choose", $options);
if (empty($group)) {
$group = $defaultGroup;
} else {
$group = $options[$group];
}
$user = new User();
$user->scenario = 'creation';
$user->first_name = $this->prompt("First name");
$user->last_name = $this->prompt("Last name");
$user->email = $this->prompt("Email");
$user->status = 1;
$user->username = $this->prompt("Username");
$user->password = $this->prompt("Password");
$user->registerRelationModel(['parent_object_id' => $group]);
if (!$user->validate()) {
\d($user->errors);
$this->stderr("User didn't validate!");
exit;
}
$individual = $user->guessIndividual();
if (empty($individual)) {
if (!Console::confirm("No matching individual was found. Continue?")) {
$this->stderr("Bye!");
exit;
}
} elseif (is_object($individual)) {
$user->object_individual_id = $individual->primaryKey;
if (!Console::confirm("Matching individual was found ({$individual->descriptor})! Continue?")) {
$this->stderr("Bye!");
exit;
}
} else {
$options = [];
$i = 1;
$this->out("Possible Individual Matches...");
foreach ($individual as $ind) {
$options[$i] = $ind->primaryKey;
$this->out("{$i}) {$ind->descriptor}");
$i++;
}
$user->object_individual_id = Console::select("Choose", $options);
}
if ($user->save()) {
$this->out("User created!");
} else {
\d($user->errors);
$this->out("Error creating user!");
}
}