Yii Framework Forum: How To Call Controller/action In Console Command - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

How To Call Controller/action In Console Command Rate Topic: -----

#1 User is offline   xander 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 14
  • Joined: 10-September 12

Posted 13 April 2013 - 09:24 AM

I had create an action in controller and wish to reuse it by calling it in console command. my action in controller work fine in web but can't call in command console. Please help.

class MyExampleController extends Controller
{
...
public function actionShowMe()
{
echo "testing";
}
...


}
-------------------------------------------------------------------------------------------
class GoCommand extends CConsoleCommand
{
public function run($args)
{
echo $this->renderInternal('myExample/showMe');
}
}
0

#2 User is offline   sensorario 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,797
  • Joined: 07-September 10
  • Location:Cesena (Italy)

Posted 13 April 2013 - 10:07 AM

I suggest you another way. For example you can create your own component:
class YourComponent
{
  public static function yourMethod()
  {
    echo "hello!";
  }
}


And call it from each methods you need:
class MyExampleController extends Controller
{
  public function actionShowMe()
  {
    YourComponent::yourMethod();
  }
}

class GoCommand extends CConsoleCommand
{
  public function run($args)
  {
    YourComponent::yourMethod();
  }
} 

0

#3 User is offline   xander 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 14
  • Joined: 10-September 12

Posted 13 April 2013 - 11:17 AM

View Postsensorario, on 13 April 2013 - 10:07 AM, said:

I suggest you another way. For example you can create your own component:
class YourComponent
{
  public static function yourMethod()
  {
    echo "hello!";
  }
}


And call it from each methods you need:
class MyExampleController extends Controller
{
  public function actionShowMe()
  {
    YourComponent::yourMethod();
  }
}

class GoCommand extends CConsoleCommand
{
  public function run($args)
  {
    YourComponent::yourMethod();
  }
} 



Thanks for the suggestion. It help but in my case I use mpdf extension and I need to renderPartial for my dataProvider. How can I do it?


        public static function send()
        {
                  ......
                  $officer = new CArrayDataProvider($tmpOfficer, array(
                                    'pagination'=>array(
                                        'pageSize'=>count($tmpOfficer),
                                    ),
                  ));

                  $mPDF1 = Yii::app()->ePdf->mpdf();

                  $mPDF1 = Yii::app()->ePdf->mpdf('en-x','A4-L');
                  $stylesheet = file_get_contents(Yii::getPathOfAlias('webroot') . '\..\css\screen.css');
                  $mPDF1->WriteHTML($stylesheet, 1);
                  $mPDF1->WriteHTML($this->renderPartial('blastEmail2',array(
                            'dataProvider'=>$officer,
                            'title'=>"<b>" . $alarm->name . "</b><br/>" . $alarm->alert_day,
                            'email'=>$to,
                  ), true));
                  ...............
        }


I can't use $this->renderPartial. How to do it?
0

#4 User is offline   Mike 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 2,993
  • Joined: 06-October 08
  • Location:Upper Palatinate

Posted 14 April 2013 - 03:20 PM

I had do solve a similar problem when i wrote my pdfable extension. You can look at the PpdfFile class for some inspiration. Maybe you even want to use my extension instead. It's based on wkhtmltopdf and comes with command line support.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users