I am too newbie in Cake to go after HABTM yet... i see your point
tough and will put it into my todo list, specially since the
performance will be improved immensely if this scales, and i better
start by thinking performant from early days.
One followup question i had on this was that, after putting my user_id
into work on the index (list keywords), i immediatly noticed that
edit, view, remove, .... are now "hackable" by passing a different id
in the url. IE for now i can access other user's keywords.
Is there any best practice here to apply some rules to all actions
(edit, view, remove), or must that be done manually one by one. As i
stated before, I started with a baked MVC, and am now trying to adapt
it closer to my needs.
Again, thanks for being helpful. This cakephp groups really rocks.
I've been learning a lot just by reading it
AGD
On May 4, 9:33 pm, brian <bally.z...@gmail.com> wrote:
> That looks like it should work with what I posted earlier. Did you try it?
>
> 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 <anibaldam...@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