dongxiusuo9881 2014-02-26 15:13
浏览 58
已采纳

CConsoleApplication及其行为没有名为“getViewRenderer”的方法或闭包

I am trying to render a page and convert it to pdf then send it as email. i am getting the following error

./yiic weeklystatusreport 
exception 'CException' with message 'CConsoleApplication and its behaviors do not have a method or closure named "getWidgetFactory".' in /opt/yii-1.1.14.f0fee9/framework/base/CComponent.php:266
Stack trace:
#0 [internal function]: CComponent->__call('getWidgetFactor...', Array)
#1 /opt/yii-1.1.14.f0fee9/framework/web/CBaseController.php(146): CConsoleApplication->getWidgetFactory()
#2 /opt/yii-1.1.14.f0fee9/framework/web/CBaseController.php(172): CBaseController->createWidget('zii.widgets.gri...', Array)
#3 /opt/paradox/protected/views/viewWebprojectreport/weekly_status_graph.php(198): CBaseController->widget('zii.widgets.gri...', Array)
#4 /opt/yii-1.1.14.f0fee9/framework/web/CBaseController.php(126): require('/opt/paradox/pr...')
#5 /opt/paradox/protected/commands/WeeklystatusreportCommand.php(201): CBaseController->renderInternal('/opt/paradox/pr...', Array, true)
#6 /opt/yii-1.1.14.f0fee9/framework/console/CConsoleCommandRunner.php(71): WeeklystatusreportCommand->run(Array)
#7 /opt/yii-1.1.14.f0fee9/framework/console/CConsoleApplication.php(92): CConsoleCommandRunner->run(Array)
#8 /opt/yii-1.1.14.f0fee9/framework/base/CApplication.php(180): CConsoleApplication->processRequest()
#9 /opt/yii-1.1.14.f0fee9/framework/yiic.php(33): CApplication->run()
#10 /opt/paradox/protected/yiic.php(7): require_once('/opt/yii-1.1.14...')
#11 /opt/paradox/protected/yiic(4): require_once('/opt/paradox/pr...')

in the console app i have the following code.

public function run($args)
    {
        $graph = 4;
        $graphs = array();
        $arr = array();
        $where = array(
                array("PROJCODE"=>array("Woking","Cairo"),"MC"=>array("MC")),
                array("PROJCODE"=>array("Houston","Cairo"),"MC"=>array("MC")),
                array("PROJCODE"=>array("Jakarta"),"MC"=>array("MC")),
                array("MC"=>array("P")),
        );
        $title = array(
                array("Woking & Cairo"),
                array("Houston & Cairo"),
                array("Jakarta"),
                array(""),
        );



        for ($i = 0; $i < $graph; $i++) {

            $model=new ViewWebprojectreport('weeklystatus');
            $model->unsetAttributes();
            $dataProvider = $model->weeklystatus($where[$i] );
            $dataProvider->pagination->pageSize = $model->count();
            //print_r($dataProvider);
            $blank = array();
            foreach ($dataProvider->getData() as $data) {
                $blank[] = $data;
            }

            $count = 0;
            $command = array();

            foreach ($dataProvider->getData() as $data) {
                $count++;
                $command[$count]["PROJECT"] = $data->PROJECT;
                $command[$count]["StartDATE"] = $data-> StartDATE;
                $command[$count]["ProjectEndDate"] = $data-> ProjectEndDate;
                $command[$count]["PERCENT"] = $data-> PERCENT;
                $command[$count]["MC"] = $data-> MC;
                $command[$count]["MC"] = $data->ActualEndDate;

                $count++;
            }
            $totalprojects = $count;

            $cat = array();
            $totalLength = array();
            $schedule = array();
            $complete = array();
            $planned = array();

            $totalprojects = count($command);
            $scrollcount = 0;
            if(count($command)>20)
                $scrollcount = count($command) - 10; // set scrollbar depending on records returned

            foreach ($command as $key => $value) {
                $cat[] = $value['PROJECT'];
                $date_from = (strtotime($value['StartDATE']) )*1000;
                $date_to = (strtotime($value['ProjectEndDate']) + 1*86400)*1000;


                if($value['MC'] == -1)
                    $totalLength[] = array("low"=>$date_from,"high"=>$date_to, "color"=>"#2f7ed8");
                elseif($value['MC'] == 0)
                $totalLength[] = array("low"=>$date_from,"high"=>$date_to, "color"=>"#0d233a");
                else
                    $totalLength[] = array($date_from,$date_to);

                $today = time();
                $startdate = strtotime($value['StartDATE']);
                $enddate = strtotime($value['ProjectEndDate']);


                if( $value['ProjectEndDate'] == ""){
                    $enddate = $startdate;
                }

                $diff_total = $enddate - $startdate;
                $diff_today = $today - $startdate;

                $schedule[] = array( $date_from,  $today*1000 );

                // work out number of days completed by percent complete of project
                $percentage_to_get = round((float)$value['PERCENT'],2);
                $percentage_of_days =  ((int)$value['PERCENT'] == 0)? 0 : floor($diff_total/100*$percentage_to_get);
                $percentComplete = (($startdate + $percentage_of_days)+ 1*86400)*1000;

                $complete[] = (float) $value['PERCENT'];
                $planned[]=($diff_today != 0 && $diff_total != 0) ?  ( ((($today - $startdate) /  ($enddate - $startdate))*100) > 100 ) ? 100 : (($today - $startdate) /  ($enddate - $startdate))*100 :  0;

            }

            $arr[] = array(
                    //'cat'=>$cat,
                    //"data"=>$totalLength,
                    //"complete"=>$complete,
                    //"planned"=>$planned,
                    //"totalprojects"=>$count,
                    //"title"=>$title[$i],
                    "key"=>$i,
                    "dataProvider"=>$dataProvider
            );
            $rotation = (count($command) < 5) ? 0 : -315;
            $json = json_encode(array(
                    "chart"=>array(
                            "type"=>'column',
                            "width"=>1000,
                            "height"=>350
                    ),
                    "title"=>array(
                            "text"=>$title[$i]
                    ),
                    "xAxis"=>array(
                            "categories"=>$cat,
                            "labels"=>array(
                                    "rotation"=>$rotation,
                                    "align"=>'left',
                                    "style"=>array(
                                            "fontSize"=>'8px',
                                            "fontFamily"=>'Verdana, sans-serif',
                                            "width"=>"75px"
                                    )
                            )
                    ),
                    "yAxis"=>array(
                            "min"=>0,
                            "max"=>100,
                            "title"=>array(
                                    "text"=>'% COMPLETE'
                            ),
                            "tickInterval"=>10
                    ),
                    "plotOptions"=>array(
                            "column"=>array(
                                    "pointPadding"=> 0,
                                    "borderWidth"=> 0
                            )
                    ),
                    "legend"=>array(
                            "enabled"=>true,
                            "verticalAlign"=>'middle',
                            "align"=>'right',
                            //"floating"=> true
                    ),
                    "credits"=>array(
                            "enabled"=> false
                    ),
                    "series"=>array(
                            array(
                                    'name'=>'Planned',
                                    'data'=>$planned,
                                    'color'=> "rgb(91,155,213)"
                            ),
                            array(
                                    "name"=>'Actual',
                                    "data"=>$complete,
                                    "color"=>'rgb(237,125,49)'
                            )
                    )
            ));
            exec("pwd");

            $file = "/opt/paradox/protected/extensions/highcharts/exporting-server/php/php-batik/temp/$i.json";
            // Write the contents back to the file
            file_put_contents($file, $json);
            // generates images to use for weekly status report
            shell_exec("/usr/local/bin/phantomjs /opt/paradox/protected/extensions/highcharts/exporting-server/phantomjs/highcharts-convert.js -infile protected/extensions/highcharts/exporting-server/php/php-batik/temp/${i}.json -outfile images/$i.png -constr Chart");
    }

    //$this->renderPartial('weekly_status_graph', array("arr"=>$arr));
    //exit();
    $filename = 'weeklystatusreport_'.date('Y-m-d').'.pdf';

    Yii::import('application.extensions.pdfable.WkHtmlToPdf');


    $pdf = new WkHtmlToPdf(array(
            'no-outline',         // Make Chrome not complain
            'margin-top'    => 10,
            'margin-right'  => 5,
            'margin-bottom' => 10,
            'margin-left'   => 5,
    ));
    $pdf->setOptions(array(
            'orientation' => 'landscape'
    ));

    $ccc = new CController('context');
    $html = $ccc->renderFile('/opt/paradox/protected/views/viewWebprojectreport/weekly_status_graph.php', array("arr"=>$arr), true);

    // Add a HTML file, a HTML string or a page from a URL
    $pdf->addPage($html);


    // Add a cover (same sources as above are possible)
    //$pdf->addCover('mycover.html');

    // Add a Table of contents
    //$pdf->addToc();

    // Save the PDF

    $pdf->saveAs("/tmp/$filename");
}
  • 写回答

2条回答 默认 最新

  • donglei2288 2014-02-27 01:27
    关注

    I believe you are trying to use CGridView in your view file.

    The console application cannot really use widgets like you want it to. You can read more about it here: http://www.yiiframework.com/forum/index.php/topic/23459-cgridview/

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 C#调用python代码(python带有库)
  • ¥15 矩阵加法的规则是两个矩阵中对应位置的数的绝对值进行加和
  • ¥15 活动选择题。最多可以参加几个项目?
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?
  • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)
  • ¥20 怎么在stm32门禁成品上增加查询记录功能
  • ¥15 Source insight编写代码后使用CCS5.2版本import之后,代码跳到注释行里面
  • ¥50 NT4.0系统 STOP:0X0000007B