當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Console::select方法代碼示例

本文整理匯總了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);
 }
開發者ID:avron99,項目名稱:delayed-orders,代碼行數:13,代碼來源:Controller.php

示例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!");
     }
 }
開發者ID:psesd,項目名稱:cascade-lib,代碼行數:71,代碼來源:UsersController.php


注:本文中的yii\helpers\Console::select方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。