OK so here is my solution for changing order in the lists:

Firstly, we need to alter table and add additional columns such "lft
INT(10) NULL, "rght INT(10) NULL" and "parent_id INT(10) NULL"

Even if you want to just change order on the list, "parent_id" field
is needed.

And now model:

<?php

class News extends AppModel {

        var $name = 'News';
        var $actsAs = array('Tree');
        var $order = 'News.lft ASC';

}

?>


controller:

        function admin_moveup($id = null){

                $news = $this->News->findById($id);

        if ( empty($news) ) {
            $this->Session->setFlash('Nie ma takiego newsa!');
            $this->redirect(array('action' => 'index'), null, true);
        }

        $this->News->id = $news['News']['id'];

        $this->News->moveup($this->News->id, 1);

                $this->Session->setFlash("News został przesunięty!");
        $this->redirect(array('action' => 'index'), null, true);
        }


admin_movedown is the same, the only one diffrence is method movedown
(args)..

Cheers


On 21 Lip, 19:03, "mariusz.lewandowski" <[email protected]> wrote:
> Well, that's true but my assumption was to save record with position
> number the same as ID. That would protect me before doubling values.
> So in case I have unique values - why it doesn't work?
>
> I also tried saveField but it behaves strangely - sometimes it works
> sometimes doesn't ...
>
> On Jul 21, 6:53 pm, brian <[email protected]> wrote:
>
> > This is unlikely to work the way that you want. The problem is that
> > you change one record's position to, eg. 23 but there may be another
> > record that already has that value. In order for this to work, you'll
> > have to re-sort the entire table.
>
> > You might want to use TreeBehavior to take advantage of its moveup() &
> > movedown() methods. You can do this even if your records are all on
> > the same level, hierarchically.
>
> > 2009/7/21 mariusz.lewandowski <[email protected]>:
>
> > > Hello all!
>
> > > I'm trying to implement functionality in my CMS system to be able to
> > > move up/down items on the list based on "position" column.
>
> > > Here is my code:
>
> > >        public function admin_up($position) {
>
> > >                $neighbours = $this->News->find('neighbors', 
> > > array('position' =>
> > > $position));
> > >                $currentRecord = $this->News->findByPosition($position);
>
> > >                $currentRecord = $currentRecord['News'];
> > >                $previousRecord = $neighbours['prev']['News'];
>
> > >                $this->temp = $previousRecord;
>
> > >                $this->News->id = $previousRecord['id'];
> > >                $this->News->position = $currentRecord['position'];
> > >                $this->News->save();
>
> > >                $this->News->id = $currentRecord['id'];
> > >                $this->News->position = $this->temp['position'];
> > >                $this->News->save();
>
> > > //              $this->Session->setFlash("News został przesunięty!");
> > > //              $this->redirect('index');
> > >        }
>
> > > and SQL dump:
>
> > > UPDATE `news` SET `id` = 20, `position` = 23 WHERE `news`.`id` = 20
> > > UPDATE `news` SET `id` = 20, `position` = 23 WHERE `news`.`id` = 20
>
> > > it invokes bad parametrs in second call. Why? I spent for it 10 hours
> > > and still the same results...
>
> > > Please help, I'm getting confused! :S
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" 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