Although I think it'd be better practice to use a HABTM association
between these models so that Users can share Keywords. That would make
your pagination a bit more complicated but there is a way to do that,
also. Search on "cakephp paginate habtm".
On Mon, May 4, 2009 at 3:09 PM, AGD <anibaldamiao@gmail.com> wrote:
>
> Brian, thanks for your reply.
> The idea is that an user will defined several keywords.
>
> Keywords model has this defined:
>
> var $belongsTo = array(
> 'User' => array(
> 'className' => 'User',
> 'foreignKey' => 'user_id',
> 'conditions' => '',
> 'fields' => '',
> 'order' => ''
> )
> );
>
> User model has this defined:
>
> //The Associations below have been created with all possible keys,
> those that are not needed can be removed
> var $hasMany = array(
> 'Keyword' => array(
> 'className' => 'Keyword',
> 'foreignKey' => 'user_id',
> 'dependent' => false
> )
>
>
> Is that an ok definition in the model? Does it make sense and should i
> improve it?
> Thanks for your feedback
>
>
> On May 4, 12:09 am, brian <bally.z...@gmail.com> wrote:
>> Adjust the conditions in the controller's $paginate array.
>>
>> function index() {
>> $this->Keyword->recursive = 0;
>>
>> $this->paginate['conditions'] = array(
>> 'Keyword.user_id' => $user_id
>> );
>> $this->set('keywords', $this->paginate());
>>
>> }
>>
>> But this seems really strange. Does the keywords table really have a
>> user_id column? How are your models associated?
>>
>> On Sun, May 3, 2009 at 4:54 PM, AGD <anibaldam...@gmail.com> wrote:
>>
>> > Hi
>> > I've successfully added some user access control and now would like to
>> > change the views to show only keywords related to that specific user.
>> > How should i do it?
>>
>> > For instance for the keywords/index page, i have this simple
>> > controller (baked):
>>
>> > function index() {
>> > $this->Keyword->recursive = 0;
>> > $this->set('keywords', $this->paginate());
>> > }
>>
>> > but this shows all "keywords" in the DB and i would like to show only
>> > the keywords related to that specific user (the DB has an user_id).
>>
>> > Any help is appreciated.
>> > AGD
> >
>
--~--~---------~--~----~------------~-------~--~----~
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:
Post a Comment