Using Components (or whole Controllers) in a cake-shell

3 messages Options
Embed this post
Permalink
leberle

Using Components (or whole Controllers) in a cake-shell

Reply Threaded More More options
Print post
Permalink

Hi, i'm currently working on a cake-shell cron, and i got some trouble
using one of the components from my App.
I need to use a method from a component that is usally used in my
Orders-Controller, i tried:

---------------------

App::import('Component','OrderProcess');

class OrdersCronShell extends Shell
{
        var $uses = array('Order');
        var $OrderProcess = false;

        function main()
        {
                $this->OrderProcess = new OrderProcessComponent();
                $res = $this->Order->findAllByStatus('3');
                $order_ids = Set::extract('/Order/id',$res);

                $this->out("got ".count($order_ids)." pending orders");

                for ($x = 0; $x < count($order_ids); $x++) {
                        $transfer_result = $this->OrderProcess->transferOrder($order_ids
[$x]);

                        if (!($transfer_result === true)) {
                                $this->out("failed transfering order ".$order_ids[$x]."\r\n");
                        }
                }
        }
}

---------------------

which results in:
Fatal error: Call to a member function loadOrder() on a non-object in
<app_path>/controllers/components/order_process.php on line 181

The amazing thing here: transferOrder IS called (so i guess there is a
component-object), but the call to the components loadOrder function
(called from within transferOrder) fails... o_O

Then i tried wrapping the whole component-using to a Shell-Task class
(acording to the "using the mail component in a shell"-article from
the bakery) but the same error occured.....

i even tried to load the controller instead of just the component:

---------------------

App::import('Core', 'Controller');
App::import('Controller', 'Orders');

class OrdersCronShell extends Shell
{
        var $uses = array('Order');
        var $Orders;

        function main()
        {
                $this->Orders = new OrdersController();
                $this->Orders->constructClasses();

                $res = $this->Order->findAllByStatus('3');
                $order_ids = Set::extract('/Order/id',$res);

                $this->out("got ".count($order_ids)." pending orders");

                for ($x = 0; $x < count($order_ids); $x++) {
                        $transfer_result = $this->Orders->OrderProcess->transferOrder
($order_ids[$x]);

                        if (!($transfer_result === true)) {
                                $this->out("failed transfering order ".$order_ids[$x]."\r\n");
                        }
                }
        }
}

---------------------

..same error....any help?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

leberle

Re: Using Components (or whole Controllers) in a cake-shell

Reply Threaded More More options
Print post
Permalink

Solved :)

For some reason the initialization of the component failed, even if
the controllers constructClasses() is called...
solved by:

$this->Orders = new OrdersController();
$this->Orders->constructClasses();
$this->Orders->OrderProcess->initialize(&$this->Orders);

:)

On 21 Okt., 12:44, leberle <[hidden email]> wrote:

> Hi, i'm currently working on a cake-shell cron, and i got some trouble
> using one of the components from my App.
> I need to use a method from a component that is usally used in my
> Orders-Controller, i tried:
>
> ---------------------
>
> App::import('Component','OrderProcess');
>
> class OrdersCronShell extends Shell
> {
>         var $uses                       = array('Order');
>         var $OrderProcess       = false;
>
>         function main()
>         {
>                 $this->OrderProcess = new OrderProcessComponent();
>                 $res = $this->Order->findAllByStatus('3');
>                 $order_ids = Set::extract('/Order/id',$res);
>
>                 $this->out("got ".count($order_ids)." pending orders");
>
>                 for ($x = 0; $x < count($order_ids); $x++) {
>                         $transfer_result = $this->OrderProcess->transferOrder($order_ids
> [$x]);
>
>                         if (!($transfer_result === true)) {
>                                 $this->out("failed transfering order ".$order_ids[$x]."\r\n");
>                         }
>                 }
>         }
>
> }
>
> ---------------------
>
> which results in:
> Fatal error: Call to a member function loadOrder() on a non-object in
> <app_path>/controllers/components/order_process.php on line 181
>
> The amazing thing here: transferOrder IS called (so i guess there is a
> component-object), but the call to the components loadOrder function
> (called from within transferOrder) fails... o_O
>
> Then i tried wrapping the whole component-using to a Shell-Task class
> (acording to the "using the mail component in a shell"-article from
> the bakery) but the same error occured.....
>
> i even tried to load the controller instead of just the component:
>
> ---------------------
>
> App::import('Core', 'Controller');
> App::import('Controller', 'Orders');
>
> class OrdersCronShell extends Shell
> {
>         var $uses                       = array('Order');
>         var $Orders;
>
>         function main()
>         {
>                 $this->Orders = new OrdersController();
>                 $this->Orders->constructClasses();
>
>                 $res = $this->Order->findAllByStatus('3');
>                 $order_ids = Set::extract('/Order/id',$res);
>
>                 $this->out("got ".count($order_ids)." pending orders");
>
>                 for ($x = 0; $x < count($order_ids); $x++) {
>                         $transfer_result = $this->Orders->OrderProcess->transferOrder
> ($order_ids[$x]);
>
>                         if (!($transfer_result === true)) {
>                                 $this->out("failed transfering order ".$order_ids[$x]."\r\n");
>                         }
>                 }
>         }
>
> }
>
> ---------------------
>
> ..same error....any help?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

RoBo

Re: Using Components (or whole Controllers) in a cake-shell

Reply Threaded More More options
Print post
Permalink

Hey, did you still have to use App::import for your fix?

On Oct 21, 9:29 pm, leberle <[hidden email]> wrote:

> Solved :)
>
> For some reason the initialization of the component failed, even if
> the controllers constructClasses() is called...
> solved by:
>
> $this->Orders = new OrdersController();
> $this->Orders->constructClasses();
> $this->Orders->OrderProcess->initialize(&$this->Orders);
>
> :)
>
> On 21 Okt., 12:44, leberle <[hidden email]> wrote:
>
> > Hi, i'm currently working on a cake-shell cron, and i got some trouble
> > using one of the components from my App.
> > I need to use a method from a component that is usally used in my
> > Orders-Controller, i tried:
>
> > ---------------------
>
> > App::import('Component','OrderProcess');
>
> > class OrdersCronShell extends Shell
> > {
> >         var $uses                       = array('Order');
> >         var $OrderProcess       = false;
>
> >         function main()
> >         {
> >                 $this->OrderProcess = new OrderProcessComponent();
> >                 $res = $this->Order->findAllByStatus('3');
> >                 $order_ids = Set::extract('/Order/id',$res);
>
> >                 $this->out("got ".count($order_ids)." pending orders");
>
> >                 for ($x = 0; $x < count($order_ids); $x++) {
> >                         $transfer_result = $this->OrderProcess->transferOrder($order_ids
> > [$x]);
>
> >                         if (!($transfer_result === true)) {
> >                                 $this->out("failed transfering order ".$order_ids[$x]."\r\n");
> >                         }
> >                 }
> >         }
>
> > }
>
> > ---------------------
>
> > which results in:
> > Fatal error: Call to a member function loadOrder() on a non-object in
> > <app_path>/controllers/components/order_process.php on line 181
>
> > The amazing thing here: transferOrder IS called (so i guess there is a
> > component-object), but the call to the components loadOrder function
> > (called from within transferOrder) fails... o_O
>
> > Then i tried wrapping the whole component-using to a Shell-Task class
> > (acording to the "using the mail component in a shell"-article from
> > the bakery) but the same error occured.....
>
> > i even tried to load the controller instead of just the component:
>
> > ---------------------
>
> > App::import('Core', 'Controller');
> > App::import('Controller', 'Orders');
>
> > class OrdersCronShell extends Shell
> > {
> >         var $uses                       = array('Order');
> >         var $Orders;
>
> >         function main()
> >         {
> >                 $this->Orders = new OrdersController();
> >                 $this->Orders->constructClasses();
>
> >                 $res = $this->Order->findAllByStatus('3');
> >                 $order_ids = Set::extract('/Order/id',$res);
>
> >                 $this->out("got ".count($order_ids)." pending orders");
>
> >                 for ($x = 0; $x < count($order_ids); $x++) {
> >                         $transfer_result = $this->Orders->OrderProcess->transferOrder
> > ($order_ids[$x]);
>
> >                         if (!($transfer_result === true)) {
> >                                 $this->out("failed transfering order ".$order_ids[$x]."\r\n");
> >                         }
> >                 }
> >         }
>
> > }
>
> > ---------------------
>
> > ..same error....any help?
>
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---