cakephp / docs

CakePHP CookBook
http://book.cakephp.org
Other
681 stars 2.58k forks source link

Please clarify expected `$tagList` format #7937

Closed mehov closed 2 hours ago

mehov commented 2 hours ago

https://book.cakephp.org/5/en/views/helpers/form.html#creating-inputs-for-associated-data

// Multiple select element for belongsToMany
// Does not support _joinData
echo $this->Form->control('tags._ids', [
    'type' => 'select',
    'multiple' => true,
    'options' => $tagList,
]);

What shoud $tagList look like? I searched that page for $tagList but there's no other mention.

I could only find https://discourse.cakephp.org/t/checkbox-checked-for-multiple-select-input-for-belongs-to-many-associations-solved/4273 via site:cakephp.org "$tagList"

dereuromark commented 2 hours ago

It would usually be an array with the id as integer key and the value as the tag name https://github.com/dereuromark/cakephp-sandbox/blob/bd1cc599ca6ad6862c969fac5fba66ca60b0cb60/plugins/Sandbox/src/Controller/TagsController.php#L77

Feel free to make a PR to fix the docs once you got it up and running.

mehov commented 2 hours ago

Alright, I just did the simplest possible $tagList = $this->Tags->find('list')->toArray() and it worked perfectly

ADmad commented 2 hours ago

@mehov You should perhaps start by doing the tutorials first. This section shows exactly what you are asking https://book.cakephp.org/5/en/tutorials-and-examples/cms/tags-and-users.html#updating-articles-to-enable-tagging.

We can't go about adding every detail in every section of the manual.

ADmad commented 2 hours ago

P.S You can also use one of the support forums instead of opening Github issues if you need help with something.

mehov commented 47 minutes ago

P.S You can also use one of the support forums instead of opening Github issues if you need help with something.

I wasn't asking for help and I found my answer myself anyway. (Although I say thank you to dereuromark for reacting very quick, probably too quick, I just haven't seen the message in time.)

I merely pointed out that the documentation could be clearer. That would lead to a better developer experience for everyone who uses it.

No need to get irritated.

mehov commented 46 minutes ago

Can see now that you updated the docs. Thank you.

ADmad commented 30 minutes ago

What shoud $tagList look like?

This very much sounds like you were asking for help rather that suggesting improvement to the docs.