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

时间:2014-02-26 15:13:43

标签: php yii console-application centos5

我正在尝试渲染页面并将其转换为pdf,然后将其作为电子邮件发送。我收到以下错误

./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...')

在控制台应用程序中我有以下代码。

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 个答案:

答案 0 :(得分:2)

我相信您正在尝试在视图文件中使用CGridView。

控制台应用程序无法真正使用您想要的小部件。您可以在此处详细了解:http://www.yiiframework.com/forum/index.php/topic/23459-cgridview/

答案 1 :(得分:0)

我使用iReport extension。 它解析使用独立的免费Java应用程序iReport生成的报告。 虽然如果你使用Netbeans将llok带到iReport Netbeans extension

您无法使用某些高级报告功能,但可以轻松创建包含图像,组等的报告,并使用Yii将其导出为PDF。