Saturday, October 4, 2008

Re: how to display a different field name from the database in the model

You should really look into changing the variable name in the code.
With search&replace this may be the best option.

Otherwise, you could do that in the model with the afterFind callback.
Just copy the field:
$model['name'] = $model['name_en_gb'];

But you're setting yourself up for all kinds of problems with this, as
you'll have to convert back and forth between the database and
application.

On 5 Oct 2008, at 15:36, robert123 wrote:

>
> hi,
>
> Thank you, I have a cakephp application, the product model has the
> 'name' field, and all the codes, that is the controller, view, call
> that field as 'name'.
>
> but right now the product table in the database which has the field
> 'name' has been changed to 'name_en_gb', I am wondering, is there any
> small change in the model I can do such that it will read the
> 'name_en_gb' field in the product table in the database, but at the
> code level, the view, controller, etc can access it using the 'name'
> field.
>
> Thank you
>
> On Oct 5, 2:21 pm, "David C. Zentgraf" <dec...@gmail.com> wrote:
>> If you mean "display to the user" I don't see where the problem is.
>> If you're talking about scaffolding, just make a proper view.
>> If you mean "change internally" it's more hassle than it's worth
>> IMHO.
>>
>> Can you clarify a bit what you want to do and where you're stuck?
>>
>> On 5 Oct 2008, at 10:32, robert123 wrote:
>>
>>
>>
>>> hi
>>
>>> in my database there is a field
>>
>>> which is name_en_gb
>>
>>> in my model
>>
>>> i wanted it to read the field, but display it as the field
>>
>>> name
>>
>>> can anyone let me know how to do it, thank you
> >


--~--~---------~--~----~------------~-------~--~----~
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 cake-php+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

No comments: