Any hints? :(

On 22 Lip, 12:44, "mariusz.lewandowski" <[email protected]> wrote:
> Hi again,
>
> i faced second with sorting lists. I have my database table called
> "portfolios" which belongsTo "category":
>
> (id, title, category_id, parent_id, lft, rght).
>
> As you can see it is related model to Category:
>
> class Portfolio extends AppModel {
>
>         var $name = 'Portfolio';
>         var $actsAs = array('Tree' => array('scope' => 'Portfolio'));
>         var $order = 'Portfolio.lft ASC';
>
>         var $belongsTo = array(
>                 'Category' => array(
>                         'className'  => 'Category',
>                         'foreignKey' => 'category_id',
>                         'dependent' => true,
>                 )
>         );
>
>         var $hasMany = array(
>         'Image' => array(
>             'className'     => 'Image',
>             'foreignKey'    => 'portfolio_id',
>             'dependent' => true
>         )
>     );
>
> }
>
> I made simple "Move" component to simplify moving elements on the
> lists:
>
> class MoveComponent extends Object {
>
>         private $model;
>         var $components = array('Session');
>
>         function initialize(&$controller, $settings = array()) {
>                 $this->controller =& $controller;
>         }
>
>         function up($modelName, $id, $redirectAction, $actionId = null) {
>
>                 $this->model = ClassRegistry::init($modelName);
>
>                 $object = $this->model->findById($id);
>
>         if (empty($object)) {
>
>             $this->Session->setFlash("Brak takiego obiektu!");
>                 $this->controller->redirect(array(
>                                                                 'action' => 
> $redirectAction,
>                                                                         'id' 
> => $actionId,
>                                                                         ), 
> null, true);
>         } else {
>
>                 $this->model->id = $object[$modelName]['id'];
>
>                 $this->model->moveup($this->model->id, 1);
>
>                         $this->Session->setFlash("Obiekt został 
> przesunięty!");
>                         $this->controller->redirect(array(
>                                                                 'action' => 
> $redirectAction,
>                                                                 'id' => 
> $actionId,
>                                                         ), null, true);
>         }
>         }
>
> }
>
> and then invocation in my controller :
>
>         public function admin_moveup($id = null) {
>                 $this->Move->up('Portfolio', $id, 'index');
>         }
>
> First problem was with saving portfolio to the database - it happen
> that lft and rght values were NULL. I found 
> tickethttps://trac.cakephp.org/ticket/5505
> where people suggest detaching and attacing behvaiour before saving.
> So i did it and it worked.
>
> The problem is with moveup/moveup - nothing happen..
>
> Do you know how to solve it ? My other tables works fine (news etc..)
> but they are not related to any other tables..
>
> Thnank's for help!
--~--~---------~--~----~------------~-------~--~----~
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