PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, April 22, 2022

[FIXED] How to change cakephp selection field after bake relational table ?

 April 22, 2022     cakephp, cakephp-2.3     No comments   

Issue

I have two table users and Areas.Areas has a relation with users.So I have add users_id in Areas table.After bake I get the output fine.But here in areas add form user field is showing users_id in select box.Here I want to show users_name.How can I change it?

Here is the model code

MadAreas' => array(
            'className' => 'MadAreas',
            'foreignKey' => 'users_id'
)

In controller

$madAreas = $this->MadArea->Users->find('list');

In add.ctp

 echo $this->Form->input('users_id',array( 'label' => false, 'class'=>'form-control' ));

Solution

Try specifying the fields you want in your find statement:

$madAreas = $this->MadArea->Users->find('list', array(
                                                'fields' => array('id','username')
                                                )
                                       );

Changing the $displayField in the model as mentioned in @mponos-george's answer should do it anyways, just make sure you clear your Cache files after changing the model value.



Answered By - Ayman Bedair
Answer Checked By - Dawn Plyler (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing