How to use withKey method of name class

Best Prophecy code snippet using name.withKey

Tree.php

Source:Tree.php Github

copy

Full Screen

...79 public $optionAttrs = [];80 /**81 * @var string 关联表主键值前缀,为了区分原表的主键值82 */83 public $withKeyPrefix = 'cw-';84 /**85 * @var array 关联表元素的 HTML 属性86 */87 public $withOptions = [];88 /**89 * @var string|boolean 是否添加提示信息标题90 * -string 指定的文本提示信息91 * -false 不添加提示信息92 * -true 自动设置,如果设置了模型,将会自动填充,否则使用默认文本信息93 */94 public $header = true;95 /**96 * @var array 提示信息标题的 HTML 属性97 */98 public $headerOptions = [];99 /**100 * @var Closure 每添加一个元素前的回调方法101 */102 public $beforeItem = null;103104 /************************* 以下属性均为程序运算需要,不要尝试从外部进行复制 *************************/105 /**106 * @var array 下拉标签中的元素数据107 */108 protected $items = [];109 /**110 * @var array 数据库直接查询出来的数据111 */112 protected $data = [];113 /**114 * @var string select标签的name属性名称115 */116 protected $name = '';117 /**118 * @var array 关联表的数据119 */120 protected $withData = [];121 /**122 * @var string 关联表的主键123 */124 protected $withKey;125 /**126 * @var string 关联表的显示字段127 */128 protected $withValue;129 /**130 * @var string name属性的值131 */132 private $_name = null;133134 /**135 * 初始化136 */137 public function init()138 {139 parent::init();140 // 初始化模型141 if ($this->query instanceof \yii\db\ActiveQuery && $this->model === null) {142 $this->model = new $this->query->modelClass;143 }144 // 判断是否设置关联表的层级关系输出145 if ($this->with === null && $this->query->with) {146 $this->with = current($this->query->with);147 }148 // 设置关联表相关信息149 if ($this->with) {150 if (!$this->withName) {151 throw new InvalidParamException("通过 \$query 的 `with()` 方法进行关联查询后,必须设置 [withName],指定要显示的关联表字段!");152 } else {153 if (is_string($this->withName)) {154 $this->withKey = $this->key;155 $this->withName = (array) $this->withName;156 } else {157 $this->withKey = key($this->withName);158 }159 $this->withValue = current($this->withName);160 }161 162 if ($this->withQuery instanceof \yii\db\ActiveQuery) {163 $withModel = new $this->withQuery->modelClass;164 } else {165 $withFunc = 'get' . ucfirst($this->with);166 $withQuery = $this->model->{$withFunc}();167 $withModel = new $withQuery->modelClass;168 $withQuery = $withModel::find();169 if ($this->withQuery instanceof \Closure) {170 call_user_func($this->withQuery, $withQuery);171 }172 $this->withQuery = $withQuery;173 }174 }175 // 如果有设置模型,获取所有字段176 if ($this->model !== null) {177 if ($this->with) {178 $attributes = $withModel->attributes();179 } else {180 $attributes = $this->model->attributes();181 }182 }183 // 字段名称设置检查184 if (!empty($attributes)) {185 if (!in_array($this->pid, $attributes)) {186 $model = $this->model;187 throw new InvalidParamException("{$model::className()} 对应的表中没有 `{$this->pid}` 字段!");188 }189 if (!in_array($this->sort, $attributes)) {190 $this->sort = null;191 }192 // 自动校正主键193 $this->key = current($this->model->primaryKey());194 }195 // 其他参数初始化196 $this->select = array_unique(array_merge($this->select, $this->optionAttrs));197 }198199 /**200 * 以 select 标签形式输出数据201 * 202 * @param string $field 显示<option>的[html]值的字段名称203 * @param mixed $selection 选中值204 * @param array $options 配置参数,配置`name`来修改默认的设定值205 * @return string select 标签的 HTML 代码206 */207 public function dropDownList($field, $selection = '', $options = [])208 {209 $this->name = $field;210211 $this->prepareItems();212213 $items = [];214 foreach ($this->items as $item) {215 $items[$item['key']] = $item['text'];216 $item['options'][$item['key']]['data-text'] = $item['value'];217 $options['options'][$item['key']] = $item['options'][$item['key']];218 foreach ($this->optionAttrs as $attr) {219 $options['options'][$item['key']]['data-' . $attr] = ArrayHelper::getValue($item, $attr, '');220 }221 }222 $options['encodeSpaces'] = true;223 $name = ArrayHelper::getValue($options, 'name', $this->getName());224225 return Html::dropDownList($name, $selection, $items, $options);226 }227228 /**229 * 获取元数据230 * 231 * @param string $name 用作当 [name] 属性的字段名称232 * @return array233 */234 public function getItems($name)235 {236 $this->name = $name;237238 $this->prepareItems();239240 return $this->items;241 }242243 /**244 * 添加提示信息标题245 */246 protected function addHeaderItem()247 {248 if ($this->header === true) {249 if ($this->model && method_exists($this->model, 'attributeLabels') && !empty($this->model->attributeLabels()[$this->getName()])) {250 $header = $this->model->attributeLabels()[$this->getName()];251 } else {252 $header = '请选择...';253 }254 array_unshift($this->items, ['key' => '', 'value' => $header, 'text' => $header, 'options' => ['' => $this->headerOptions]]);255 } elseif (is_string($this->header)) {256 array_unshift($this->items, ['key' => '', 'value' => $this->header, 'text' => $this->header, 'options' => ['' => $this->headerOptions]]);257 }258 }259260 /**261 * 初始化数据262 */263 protected function prepareItems()264 {265 if ($this->with) {266 if ($this->sort) {267 $this->withQuery->addOrderBy($this->sort);268 }269 $this->withData = $this->withQuery->indexBy($this->withKey)->asArray()->all();270 $this->data = $this->query->asArray()->all();271272 $pid = $this->getItemParentId($this->withData);273 $this->setWithItems($pid);274 } else {275 if ($this->sort) {276 $this->query->addOrderBy($this->sort);277 }278 $this->data = $this->query->indexBy($this->key)->asArray()->all();279280 $pid = $this->getItemParentId($this->data);281 $this->setItems($pid);282 }283284 $this->addHeaderItem();285 }286287 /**288 * 设置非关联型的元素289 */290 protected function setItems($pid = '0', $recursionLevel = 0)291 {292 $recursionLevel++;293 foreach ($this->data as $key => $row) {294 if ($row[$this->pid] === $pid) {295 if ($this->beforeItem !== null && !call_user_func($this->beforeItem, $row)) {296 continue;297 }298 if ($recursionLevel === 1) {299 $prefix = '★';300 } else {301 $prefix = str_repeat(' ', ($recursionLevel - 2) * 3) . '┕ ';302 }303 $value = $this->getNameValue($row);304 $item = [305 'key' => $row[$this->key],306 'text' => $prefix . $value,307 'value' => $value,308 ];309 foreach ($this->select as $select) {310 $item[$select] = $row[$select];311 }312 $this->items[] = $item;313 $this->setItems($row[$this->key], $recursionLevel);314 unset($this->data[$key]);315 }316 }317 }318319 /**320 * 设置关联型的元素321 */322 protected function setWithItems($pid = '0', $recursionLevel = 0)323 {324 $recursionLevel++;325 foreach ($this->withData as $key => $row) {326 if ($row[$this->pid] === $pid) {327 $withPrefix = str_repeat(' ', ($recursionLevel - 1) * 3) . '★';328 $withKey = $this->withKeyPrefix . $row[$this->withKey];329 $withValue = $row[$this->withValue];330 $this->items[$withKey] = [331 'key' => $withKey,332 'text' => $withPrefix . $withValue,333 'value' => $withValue,334 'options' => [$withKey => $this->withOptions]335 ];336 foreach ($this->data as $k => $item) {337 if ($item[$this->with][$this->withKey] == $row[$this->withKey]) {338 $prefix = str_repeat(' ', ($recursionLevel - 1) * 3) . ' ┕ ';339 $value = $this->getNameValue($item);340 $this->items[$item[$this->key]] = [341 'key' => $item[$this->key],342 'text' => $prefix . $value,343 'value' => $value344 ];345 foreach ($this->select as $select) {346 $this->items[$item[$this->key]][$select] = $item[$select];347 }348 unset($this->data[$k]);349 }350 }351 unset($this->withData[$key]);352 $this->setWithItems($row[$this->withKey], $recursionLevel);353 }354 }355 }356357 /**358 * 获取关联表对应字段的值359 */360 protected function getNameValue($item)361 {362 if (strpos($this->name, '.') !== false) {363 $relations = explode('.', $this->name);364 $name = array_pop($relations);365 $row = $item;366 foreach ($relations as $relation) { ...

Full Screen

Full Screen

Index.php

Source:Index.php Github

copy

Full Screen

...35 continue;36 }37 if (endsWith($field, '@')) {38 $field = substr($field, 0, -1);39 list($items, $withTable, $withKey) = explode("/", $condition);40 foreach ($allData[$items] as $keyNum => $item) {41 $data1 = clone $data;42 $data1 = $data1->where($field, $allData[$items][$keyNum][$withKey]);43 $allData[$items][$keyNum][$sub] = $data1->select();44 // $allData[$items][$keyNum][$sub] = $data->select();45 // $allData[$items][$keyNum][$sub] = $data->getLastSql();46 }47 continue;48 }49 }50 }51 continue;52 }53 // 这里应该使用递归 end54 $data = Db::table($table);55 // $data = clone $data1;56 foreach ($where as $field => $condition) {57 if (endsWith($field, '@')) {58 $field = substr($field, 0, -1);59 // list($withTable, $withKey) = explode("/", $condition);60 // list($items, $withTable, $withKey) = explode("/", $condition);61 $explodeArr = explode("/", $condition);62 if (count($explodeArr) == 3) {63 // list($items, $withTable, $withKey) = $explodeArr;64 // // $data = $data->where($field, $allData[$items][$withTable][$withKey]);65 // $allData['aaaaa'] = $allData[$items][$withTable][$withKey];66 $allData['aaaaa'] = $explodeArr;67 }elseif (count($explodeArr) == 2) {68 list($withTable, $withKey) = $explodeArr;69 $data = $data->where($field, $allData[$withTable][$withKey]);70 }71 continue;72 }73 if ($field === "@column") {74 $data = $data->field($condition);75 continue;76 }77 $data = $data->where($field, $condition);78 // $allData['dddd'] .= $allData['dddd'] ? $allData['dddd'] : $table;79 $allData['sub'] = $sub;80 $allData['table'] = $table;81 // $allData[$sub][$table] = $data->select();82 }83 // $allData[$sub][$table] = $data->select();...

Full Screen

Full Screen

LinkResolverSpec.php

Source:LinkResolverSpec.php Github

copy

Full Screen

...13 DefinitionInterface $definition,14 \stdClass $object15 ) {16 $this->beConstructedWith($router, $identityResolver);17 $router->generate('bravesheep_crudify.index', Argument::withKey('mapping'))->will(function ($args) {18 return '/' . $args[1]['mapping'] . '/index';19 });20 $router->generate('bravesheep_crudify.new', Argument::withKey('mapping'))->will(function ($args) {21 return '/' . $args[1]['mapping'] . '/new';22 });23 $router->generate('bravesheep_crudify.create', Argument::withKey('mapping'))->will(function ($args) {24 return '/' . $args[1]['mapping'] . '/create';25 });26 $router27 ->generate(28 'bravesheep_crudify.edit',29 Argument::allOf(Argument::withKey('mapping'), Argument::withKey('id'))30 )31 ->will(function ($args) {32 return '/' . $args[1]['mapping'] . '/edit/' . $args[1]['id'];33 })34 ;35 $router36 ->generate(37 'bravesheep_crudify.update',38 Argument::allOf(Argument::withKey('mapping'),Argument::withKey('id'))39 )40 ->will(function ($args) {41 return '/' . $args[1]['mapping'] . '/update/' . $args[1]['id'];42 })43 ;44 $router45 ->generate(46 'bravesheep_crudify.delete',47 Argument::allOf(Argument::withKey('mapping'), Argument::withKey('id'))48 )49 ->will(function ($args) {50 return '/' . $args[1]['mapping'] . '/delete/' . $args[1]['id'];51 })52 ;53 $definition->getName()->willReturn('test');54 $identityResolver->getId($definition, $object)->willReturn(42);55 }56 function it_is_initializable()57 {58 $this->shouldHaveType('Bravesheep\CrudifyBundle\Resolver\LinkResolver');59 }60 function it_should_retrieve_the_index_link(DefinitionInterface $definition)61 {...

Full Screen

Full Screen

withKey

Using AI Code Generation

copy

Full Screen

1$student = new Student;2$student->name->withKey('first', 'John');3$student->name->withKey('last', 'Smith');4echo $student->name->first . ' ' . $student->name->last;5$student = new Student;6$student->name->withKey('first', 'John');7$student->name->withKey('last', 'Smith');8echo $student->name->first . ' ' . $student->name->last;9$student = new Student;10$student->name->withKey('first', 'John');11$student->name->withKey('last', 'Smith');12echo $student->name->first . ' ' . $student->name->last;13$student = new Student;14$student->name->withKey('first', 'John');15$student->name->withKey('last', 'Smith');16echo $student->name->first . ' ' . $student->name->last;17$student = new Student;18$student->name->withKey('first', 'John');19$student->name->withKey('last', 'Smith');20echo $student->name->first . ' ' . $student->name->last;21$student = new Student;22$student->name->withKey('first', 'John');23$student->name->withKey('last', 'Smith');24echo $student->name->first . ' ' . $student->name->last;25$student = new Student;26$student->name->withKey('first', 'John');27$student->name->withKey('last', 'Smith');28echo $student->name->first . ' ' . $student->name->last;29$student = new Student;30$student->name->withKey('first', 'John');

Full Screen

Full Screen

withKey

Using AI Code Generation

copy

Full Screen

1$person = new Person();2$person->withKey('name', 'Sally');3echo $person->name;4$person = new Person();5$person->withKey('age', 20);6echo $person->age;7$person = new Person();8$person->withKey('address', [9]);10echo $person->address->city;11$person = new Person();12$person->withKey('address', [13]);14echo $person->address->city;15$person = new Person();16$person->withKey('address', [17]);18echo $person->address->city;19$person = new Person();20$person->withKey('address', [21]);22echo $person->address->city;23$person = new Person();24$person->withKey('address', [25]);26echo $person->address->city;27$person = new Person();28$person->withKey('address', [29]);30echo $person->address->city;31$person = new Person();32$person->withKey('address

Full Screen

Full Screen

withKey

Using AI Code Generation

copy

Full Screen

1require_once 'name.php';2$myName = new name();3$myName->withKey('test');4echo $myName->getFirstName();5echo $myName->getLastName();6require_once 'name.php';7$myName = new name();8$myName->withKey('test');9echo $myName->getFirstName();10echo $myName->getLastName();11require_once 'name.php';12$myName = new name();13$myName->withKey('test');14echo $myName->getFirstName();15echo $myName->getLastName();16require_once 'name.php';17$myName = new name();18$myName->withKey('test');19echo $myName->getFirstName();20echo $myName->getLastName();21require_once 'name.php';22$myName = new name();23$myName->withKey('test');24echo $myName->getFirstName();25echo $myName->getLastName();26require_once 'name.php';27$myName = new name();28$myName->withKey('test');29echo $myName->getFirstName();30echo $myName->getLastName();31require_once 'name.php';32$myName = new name();33$myName->withKey('test');34echo $myName->getFirstName();35echo $myName->getLastName();36require_once 'name.php';37$myName = new name();38$myName->withKey('test');39echo $myName->getFirstName();40echo $myName->getLastName();41require_once 'name.php';42$myName = new name();43$myName->withKey('test');44echo $myName->getFirstName();45echo $myName->getLastName();

Full Screen

Full Screen

withKey

Using AI Code Generation

copy

Full Screen

1require_once('name.php');2$myname = new name('John', 'Doe');3$myname->withKey('first', 'Jane');4echo $myname->first . ' ' . $myname->last;5require_once('name.php');6$myname = new name('John', 'Doe');7$myname->withKey('last', 'Smith');8echo $myname->first . ' ' . $myname->last;9require_once('name.php');10$myname = new name('John', 'Doe');11$myname->withKey('middle', 'Paul');12echo $myname->first . ' ' . $myname->middle . ' ' . $myname->last;13require_once('name.php');14$myname = new name('John', 'Doe');15$myname->withKey('middle', 'Paul');16$myname->withKey('first', 'Jane');17$myname->withKey('last', 'Smith');18echo $myname->first . ' ' . $myname->middle . ' ' . $myname->last;19require_once('name.php');20$myname = new name('John', 'Doe');21$myname->withKey('middle', 'Paul');22$myname->withKey('first', 'Jane');23$myname->withKey('last', 'Smith');24$myname->withKey('middle', 'Mary');25echo $myname->first . ' ' . $myname->middle . ' ' . $myname->last;26require_once('name.php');27$myname = new name('John', 'Doe');28$myname->withKey('middle', 'Paul');29$myname->withKey('first', 'Jane');30$myname->withKey('last', '

Full Screen

Full Screen

withKey

Using AI Code Generation

copy

Full Screen

1$names = new names();2$names->withKey('C')->withKey('A')->withKey('B');3$names->show();4$names = new names();5$names->withKey('C')->withKey('A')->withKey('B');6$names->show();7$names = new names();8$names->withKey('C')->withKey('A')->withKey('B');9$names->show();10$names = new names();11$names->withKey('C')->withKey('A')->withKey('B');12$names->show();13$names = new names();14$names->withKey('C')->withKey('A')->withKey('B');15$names->show();16$names = new names();17$names->withKey('C')->withKey('A')->withKey('B');18$names->show();19$names = new names();20$names->withKey('C')->withKey('A')->withKey('B');21$names->show();22$names = new names();23$names->withKey('C')->withKey('A')->withKey('B');24$names->show();25$names = new names();26$names->withKey('C')->withKey('A')->withKey('B');27$names->show();28$names = new names();29$names->withKey('C')->withKey('A')->withKey('B');30$names->show();31$names = new names();32$names->withKey('C')->withKey('A')->withKey('B');

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Prophecy automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Trigger withKey code on LambdaTest Cloud Grid

Execute automation tests with withKey on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful