Re: Displaying in Input Field Value of Parent Element
Hi togehter, first i've to thank you. Both things works now very fine. But for the concatenation i've antoher question. In the Members view i can access the new variable "fullname" without any problems. But it's not getting passed down to the bill, so i can't reach it there. Do you have an idea? Thank you in advance! bye Tom On 25 Apr., 03:01, "b logica" <[EMAIL PROTECTED]> wrote: > > > In the Members table i've two columns "lastname" and "firstname". But > > > in the most cases i want to display the two names concatenated > > > ($lastname . ' ' . $firstname) for this i want to store the > > > concatenated string in a "pseudo" column "completename" (to acess it > > > with [member][completename]). How can i do this? > > > Well, I cannot understand why you want to do this... > > Probably or the same reason the other zillion or so of us want to. > This is really common. > > There are a few of ways you can approach this. The first is to do it > in your SELECT query but you might end up just fighting Cake on this. > > Another is to create an afterFind() method in your model and loop > through the array, attaching a new field to each with the concatenated > names. But you have to take into account that sometimes you'll have an > array with just one Member, other times, a list of all (or many) > Members. So your $data array will be structured differently: > > array( > ['Member'] > ['first_name'] => 'foo' > ['last_name'] => 'bar' > ... > ) > > vs. > > array( > [0] > ['Member'] > ['first_name'] => 'foo' > ['last_name'] => 'bar' > ... > [1] > ['Member'] > ['first_name'] => 'foo' > ['last_name'] => 'bar' > ... > ... > ) > > finally, you can forego all of that and use Yevgeny Tomenko's > AutoFieldBehavior:http://cakeexplorer.wordpress.com/category/model/ > > class Member extends AppModel > { > var $name = 'Member'; > > var $actsAs = array( > 'AutoField' => array( > 'full_name' => array( > 'fields' => array('first_name', 'last_name'), > 'mask' => '%s %s' > ) > ) > ); > ... > > } > > The behavior takes care of running through your data, figuring out > what structure you have. With this in place, you'll have a new field > with the concatenated name. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Displaying in Input Field Value of Parent Element
> > In the Members table i've two columns "lastname" and "firstname". But > > in the most cases i want to display the two names concatenated > > ($lastname . ' ' . $firstname) for this i want to store the > > concatenated string in a "pseudo" column "completename" (to acess it > > with [member][completename]). How can i do this? > > Well, I cannot understand why you want to do this... > Probably or the same reason the other zillion or so of us want to. This is really common. There are a few of ways you can approach this. The first is to do it in your SELECT query but you might end up just fighting Cake on this. Another is to create an afterFind() method in your model and loop through the array, attaching a new field to each with the concatenated names. But you have to take into account that sometimes you'll have an array with just one Member, other times, a list of all (or many) Members. So your $data array will be structured differently: array( ['Member'] ['first_name'] => 'foo' ['last_name'] => 'bar' ... ) vs. array( [0] ['Member'] ['first_name'] => 'foo' ['last_name'] => 'bar' ... [1] ['Member'] ['first_name'] => 'foo' ['last_name'] => 'bar' ... ... ) finally, you can forego all of that and use Yevgeny Tomenko's AutoFieldBehavior: http://cakeexplorer.wordpress.com/category/model/ class Member extends AppModel { var $name = 'Member'; var $actsAs = array( 'AutoField' => array( 'full_name' => array( 'fields' => array('first_name', 'last_name'), 'mask' => '%s %s' ) ) ); ... } The behavior takes care of running through your data, figuring out what structure you have. With this in place, you'll have a new field with the concatenated name. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Displaying in Input Field Value of Parent Element
> In my "bill add view" i've currently this entry: > > echo $form->input('member_id'); > > The result is a dropdownlist with all the ID's available in the > Members table. But here i don't want to see the ID, i want to see the > "lastname" from the "lastname" column. In your controller, setup the $names variable this way (assuming the members table has its model named Member) $_names=$this->Member->findAll("",array("Member.id","Member.lastname"),"Member.lastname asc"); $this->set("names",Set::combine($_names,"{n}.Member.id","{n}.Member.lastname")); Then, in you view : echo $form->input('member_id',array("type"=>"select","options"=>$names); Now you should have a dropdown list with members lastnames displayed. > In the Members table i've two columns "lastname" and "firstname". But > in the most cases i want to display the two names concatenated > ($lastname . ' ' . $firstname) for this i want to store the > concatenated string in a "pseudo" column "completename" (to acess it > with [member][completename]). How can i do this? Well, I cannot understand why you want to do this... --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Displaying in Input Field Value of Parent Element
Hi togehter, i'am new in the development Webapplications in CakePHP. And for the beginning i've an absolute newbie question. My DB model has at the moment two tables -> Members and Bills Member hasMany Bills Bill belongsTo Member In my "bill add view" i've currently this entry: echo $form->input('member_id'); The result is a dropdownlist with all the ID's available in the Members table. But here i don't want to see the ID, i want to see the "lastname" from the "lastname" column. Whats the best way to do this? I've a secondary question ;-) In the Members table i've two columns "lastname" and "firstname". But in the most cases i want to display the two names concatenated ($lastname . ' ' . $firstname) for this i want to store the concatenated string in a "pseudo" column "completename" (to acess it with [member][completename]). How can i do this? Thank you very much in advance! Best regards Tom --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---