All public functions in a Behavior are available directly from the
Model, a kind of mix-in. The first argument is always the model, and
it's always passed automatically.

So you do this:

$this->Project->moveUp($id);

Since I use this behavior in a lot of models, I actually have this
(excerpt):

http://bin.cakephp.org/view/77774649

(note that I generally have admin_delete(), admin_add(), admin_edit()
and admin_index() defined in the AppController and only overridden
when absolutely necessary. This saves a lot of code)

This way, if controller "CategoriesController" works on model
"Category", then the following links will work without any extra
controller or model code whatsoever:

/admin/categories/move_up/{id}
/admin/categories/move_down/{id}

[I even have a generic helper to make a mini-toolbar with view, edit,
delete and move options for a given model, so in most cases I just go
echo $tool->bar($id) for each record, and it works transparently. I'm
in to writing as little code as possible to get the job done.]


On Feb 12, 1:25 pm, sbeam <[EMAIL PROTECTED]> wrote:
> On Feb 12, 4:46 am, grigri <[EMAIL PROTECTED]> wrote:
>
> > I use that code in a lot of (admittedly small) projects, and although
> > it fits my needs, if you can suggest improvements/enhancements, I'd be
> > glad to hear them. But "it didn't quite work" doesn't really give me a
> > lot to work with.
>
> no doubt, my intention there was not to give a full bug report
> exactly ;)
>
> I tried the code and it seemed to update the position field
> incorrectly, breaking the sequence. But last night I figured out that
> I was calling it wrong from the controller, guessing from the function
> def., like this:
>
> $this->Project->moveUp($this->Project, $id);
>
> which of course is seriously wrong. First time using a behavior in
> Cake so I didn't know how to call it (and yes I did search and read).
> So your code is probably OK, may just need a line in the comments to
> show future noobs how to call it properly?
>
> $this->Project->moveUp($id);
>
> I know it is sometimes hard to understand how noobs can be so stupid,
> but that's just how it is ;)
>
> cheers,
> Sam
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to