How can I get the user firstname displayed, instead of the User_id

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

How can I get the user firstname displayed, instead of the User_id

Clement Crownrise
Note that this is my DB relationship, a user has one profile, and the proposal table has a User_id colomn, however the profile table is the one that contains the user's firstname.

Can someone help me please?

--
Sign up for our Newsletter for updates.
http://cakephp.org/newsletter/signup
 
We will soon be closing this Google Group. But don't worry, we have something better coming. Stay tuned for an updated from the CakePHP Team soon.
 
Like Us on FaceBook https://www.facebook.com/CakePHP
Follow us on Twitter http://twitter.com/CakePHP
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

CakePHP- the rapid development php framework- Users 2016-04-04 14-51-59.png (53K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: How can I get the user firstname displayed, instead of the User_id

Anja Liebermann-2
In your controller you have to fetch the user together with you proposal.
To achieve this check the following:

Check in Models your connection between proposal to user. Is it set in
both directions?

Check your find statement in the Controller Probably
ProposalsController. To which depth do you fetch the data? Do you use
Containable Behaviour? If yes you have to do some tweeks there.

Without your code I can give you no better advise, but at least you know
now where to check and whch code snippets to post to get qualified answers.

Anja



Am 04.04.2016 um 16:01 schrieb Clement Crownrise:
> Note that this is my DB relationship, a user has one profile, and the
> proposal table has a User_id colomn, however the profile table is the one
> that contains the user's firstname.
>
> Can someone help me please?
>

--
Sign up for our Newsletter for updates.
http://cakephp.org/newsletter/signup

We will soon be closing this Google Group. But don't worry, we have something better coming. Stay tuned for an updated from the CakePHP Team soon.

Like Us on FaceBook https://www.facebook.com/CakePHP
Follow us on Twitter http://twitter.com/CakePHP
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How can I get the user firstname displayed, instead of the User_id

Clement Crownrise
Thanks for your response, do you mean i should create a relationship between the proposal and the user table?

will creating a proposal "belongs to user AND a User has many Proposal", fix this problem?

As for containable behavior, please what do you mean ?


Your quick response would be appreciated.


Thanks

On Mon, Apr 4, 2016 at 5:54 PM, Anja Liebermann <[hidden email]> wrote:
In your controller you have to fetch the user together with you proposal.
To achieve this check the following:

Check in Models your connection between proposal to user. Is it set in both directions?

Check your find statement in the Controller Probably ProposalsController. To which depth do you fetch the data? Do you use Containable Behaviour? If yes you have to do some tweeks there.

Without your code I can give you no better advise, but at least you know now where to check and whch code snippets to post to get qualified answers.

Anja



Am 04.04.2016 um 16:01 schrieb Clement Crownrise:
Note that this is my DB relationship, a user has one profile, and the
proposal table has a User_id colomn, however the profile table is the one
that contains the user's firstname.

Can someone help me please?


--
Sign up for our Newsletter for updates.
http://cakephp.org/newsletter/signup

We will soon be closing this Google Group. But don't worry, we have something better coming. Stay tuned for an updated from the CakePHP Team soon.

Like Us on FaceBook https://www.facebook.com/CakePHP
Follow us on Twitter http://twitter.com/CakePHP
--- You received this message because you are subscribed to a topic in the Google Groups "CakePHP" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/cake-php/EAZoK3CB30Y/unsubscribe.
To unsubscribe from this group and all its topics, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.



--

--
Sign up for our Newsletter for updates.
http://cakephp.org/newsletter/signup
 
We will soon be closing this Google Group. But don't worry, we have something better coming. Stay tuned for an updated from the CakePHP Team soon.
 
Like Us on FaceBook https://www.facebook.com/CakePHP
Follow us on Twitter http://twitter.com/CakePHP
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How can I get the user firstname displayed, instead of the User_id

heavyKevy
In reply to this post by Clement Crownrise
How many tables do you have?
And if a first name is a property of a user, why would you put it in the profiles table and not in the users?
Which version of Cake are you using?

If I understand you correctly, you are saying you have a user that has a profile and a user has many proposals.
If that is the case, I suggest you design the Db first, then bake the 3 models using the bake console, and then adjust the profile relationship making sure that it is a HasOne relationship as specified in the documentation.

If you are using Cake 3  edit each of the table files and pick an appropriate column as the display:
$this->displayField('username');

This is the field that will be shown in select boxes when using find('list')

In your controller where you use the tables you can contain the other relationships (if they are set up in the table.php) like as follows:
in the Users controller, the Users Table is loaded automatically so you can reference it through $this->Users
The call you will need to make to search for more than 1 user will be the find('all'):
$users = $this->Users->find('all', ['contain'=>['Profiles', 'Proposals']]);
For a single user, call the get method with the id of the user:
$user = $this->Users->get($id, ['contain'=>['Profiles', 'Proposals']]);

Once you have contained the other tables you can reference the fields as follows:
$user->first_name;
$user->profile->id;
$user->proposal->id;

Hope that helps a little...
Regards,
--Kevin

--
Sign up for our Newsletter for updates.
http://cakephp.org/newsletter/signup
 
We will soon be closing this Google Group. But don't worry, we have something better coming. Stay tuned for an updated from the CakePHP Team soon.
 
Like Us on FaceBook https://www.facebook.com/CakePHP
Follow us on Twitter http://twitter.com/CakePHP
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How can I get the user firstname displayed, instead of the User_id

Clement Crownrise
How many tables do you have?
1 table for users, another for profile, another for proposal, another for comment, making 4 in total

And if a first name is a property of a user, why would you put it in the profiles table and not in the users?
Users table is tied to profile table, a profile belongs to a user. There is a relationship between the user and profile tables

Which version of Cake are you using?
Cake2.8

If I understand you correctly, you are saying you have a user that has a profile and a user has many proposals.,
I am yet to create the association between profile and proposal, I only have relationship between user and profile.

Thanks

If that is the case, I suggest you design the Db first, then bake the 3 models using the bake console, and then adjust the profile relationship making sure that it is a HasOne relationship as specified in the documentation.

If you are using Cake 3  edit each of the table files and pick an appropriate column as the display:
$this->displayField('username');

This is the field that will be shown in select boxes when using find('list')

In your controller where you use the tables you can contain the other relationships (if they are set up in the table.php) like as follows:
in the Users controller, the Users Table is loaded automatically so you can reference it through $this->Users
The call you will need to make to search for more than 1 user will be the find('all'):
$users = $this->Users->find('all', ['contain'=>['Profiles', 'Proposals']]);
For a single user, call the get method with the id of the user:
$user = $this->Users->get($id, ['contain'=>['Profiles', 'Proposals']]);

Once you have contained the other tables you can reference the fields as follows:
$user->first_name;
$user->profile->id;
$user->proposal->id;

Hope that helps a little...
Regards,
--Kevin

On Tue, Apr 5, 2016 at 12:38 PM, heavyKevy <[hidden email]> wrote:
How many tables do you have?
And if a first name is a property of a user, why would you put it in the profiles table and not in the users?
Which version of Cake are you using?

If I understand you correctly, you are saying you have a user that has a profile and a user has many proposals.
If that is the case, I suggest you design the Db first, then bake the 3 models using the bake console, and then adjust the profile relationship making sure that it is a HasOne relationship as specified in the documentation.

If you are using Cake 3  edit each of the table files and pick an appropriate column as the display:
$this->displayField('username');

This is the field that will be shown in select boxes when using find('list')

In your controller where you use the tables you can contain the other relationships (if they are set up in the table.php) like as follows:
in the Users controller, the Users Table is loaded automatically so you can reference it through $this->Users
The call you will need to make to search for more than 1 user will be the find('all'):
$users = $this->Users->find('all', ['contain'=>['Profiles', 'Proposals']]);
For a single user, call the get method with the id of the user:
$user = $this->Users->get($id, ['contain'=>['Profiles', 'Proposals']]);

Once you have contained the other tables you can reference the fields as follows:
$user->first_name;
$user->profile->id;
$user->proposal->id;

Hope that helps a little...
Regards,
--Kevin

--
Sign up for our Newsletter for updates.
http://cakephp.org/newsletter/signup
 
We will soon be closing this Google Group. But don't worry, we have something better coming. Stay tuned for an updated from the CakePHP Team soon.
 
Like Us on FaceBook https://www.facebook.com/CakePHP
Follow us on Twitter http://twitter.com/CakePHP
---
You received this message because you are subscribed to a topic in the Google Groups "CakePHP" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/cake-php/EAZoK3CB30Y/unsubscribe.
To unsubscribe from this group and all its topics, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.



--

--
Sign up for our Newsletter for updates.
http://cakephp.org/newsletter/signup
 
We will soon be closing this Google Group. But don't worry, we have something better coming. Stay tuned for an updated from the CakePHP Team soon.
 
Like Us on FaceBook https://www.facebook.com/CakePHP
Follow us on Twitter http://twitter.com/CakePHP
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How can I get the user firstname displayed, instead of the User_id

Anja Liebermann-2
In reply to this post by Clement Crownrise
Hi Clement,

if one User can make a lot of proposals you ahve a on to man relation
here and your proposals table should contain the field user_id (indexed
of course *g*)
When you the set those relations properly in your models you will get
the without further tweeking the user data with the proposal and you can
display the name.

As long as you have only 4 tables the containable behaviour will not
beof interest for you. It is useful, when you have man connected models
and want one information down the chain without fetching a lot of unused
stuff. But in your case you will not need it.

Since you seem to be in the early stage of your app I would advise you
like heavykey to set up your database like you want and bake everything
from your cake console ( I hope you have a mac or Linux system. With
Windows the cake console is nasty to use) . After baking you will have a
set of models, Controllers and views, which will give you a good
starting point for further development. That works with 2.8, too.

Although if you are just starting with your app, then I would advise you
to start with CakePhp 3.x right away.

Anja



Am 05.04.2016 um 13:04 schrieb Clement Crownrise:

> Thanks for your response, do you mean i should create a relationship
> between the proposal and the user table?
>
> will creating a proposal "belongs to user AND a User has many Proposal",
> fix this problem?
>
> As for containable behavior, please what do you mean ?
>
>
> Your quick response would be appreciated.
>
>
> Thanks
>
> On Mon, Apr 4, 2016 at 5:54 PM, Anja Liebermann <[hidden email]>
> wrote:
>
>> In your controller you have to fetch the user together with you proposal.
>> To achieve this check the following:
>>
>> Check in Models your connection between proposal to user. Is it set in
>> both directions?
>>
>> Check your find statement in the Controller Probably ProposalsController.
>> To which depth do you fetch the data? Do you use Containable Behaviour? If
>> yes you have to do some tweeks there.
>>
>> Without your code I can give you no better advise, but at least you know
>> now where to check and whch code snippets to post to get qualified answers.
>>
>> Anja
>>
>>
>>
>> Am 04.04.2016 um 16:01 schrieb Clement Crownrise:
>>
>>> Note that this is my DB relationship, a user has one profile, and the
>>> proposal table has a User_id colomn, however the profile table is the one
>>> that contains the user's firstname.
>>>
>>> Can someone help me please?
>>>
>>>
>> --
>> Sign up for our Newsletter for updates.
>> http://cakephp.org/newsletter/signup
>>
>> We will soon be closing this Google Group. But don't worry, we have
>> something better coming. Stay tuned for an updated from the CakePHP Team
>> soon.
>>
>> Like Us on FaceBook https://www.facebook.com/CakePHP
>> Follow us on Twitter http://twitter.com/CakePHP
>> --- You received this message because you are subscribed to a topic in the
>> Google Groups "CakePHP" group.
>> To unsubscribe from this topic, visit
>> https://groups.google.com/d/topic/cake-php/EAZoK3CB30Y/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to
>> [hidden email].
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>

--
Sign up for our Newsletter for updates.
http://cakephp.org/newsletter/signup

We will soon be closing this Google Group. But don't worry, we have something better coming. Stay tuned for an updated from the CakePHP Team soon.

Like Us on FaceBook https://www.facebook.com/CakePHP
Follow us on Twitter http://twitter.com/CakePHP
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.