I’m having a few issues trying to figure out the following, even reading the documentation it makes little sense…
I’ve creating the following 2 tables
partners - id - partner_type_id (partner_types id) FK
partner_types - id - partner_type
generated the code using cake bake all Partners
generated the code using cake bake all PartnerTypes
on the add, edit form for the partner the dropdown only displays the ID from the partner_type table how do I get it to display partner_type with value of id??
It sounds like the array that is being provided to the Form-control() to render the partner_type dropdown is in the form:
[ id1 => id1, id2 => id2]
You’ll want it to be
[id1 => type1, id2 => type2]
You haven’t shown any code from your controller, but probably there is a find(‘list’) that is producing this array.
Looking at this should help fix your problem:
Thanks @dreamingmind that worked
I amended this line in my Controller
$partnerTypes = $this->Partners->PartnerTypes->find('list', ['keyField' => 'id', 'valueField' => 'partner_type']);
so it is now displaying the options correctly, only thing is how do I add
<option> Select Option</option> to the start of the drop down??
'empty' => 'Select Option' in the array that you pass to the
control method). Not the array of choices that you pass in the
'options' key… Like:
echo $this->Html->input('partner_type_id', [
'options' => $partnerTypes,
'empty' => 'Select Option',
I’m now struggling with another bit of code which I can’t get my head around how to write so it doesn’t throw an error…
I have several tables using the id from the partner table as a FK I’ve managed to get slug working, but now I have done this the data isn’t displaying on the view page for the other table data how do I write the following to get them to display??
public function view($slug = null)
$partner = $this->Partners->findBySlug($slug)->firstOrFail(
'contain' => ['PartnerTypes', 'SubscriptionTypes', 'Users', 'PartnerFacilities', 'PartnerPegs', 'PartnerWatersSpecies', 'PartnersWaters'],