如何在zend framwork 1.12.19中设置disableLayout?

时间:2017-05-09 12:52:34

标签: php zend-framework

我是zend framework 1.12.19的新手,现在我将生成一个excel文件。我完成了代码。在我之间我需要将布局设置为无布局。

我已经在上面写过这些内容。但它没有用,它给了我一些错误。

 set_time_limit( 0 );

        $filename = '../data/uploaded-files/excel-uploaded/FILE.xls';
        $realPath = realpath( $filename );
        if ( false === $realPath )
        {
            touch( $filename );
            chmod( $filename, 0777 );
        }

        $filename = realpath( $filename );
        $handle = fopen( $filename, "w" );
        $finalData = array();
        $data = array
                    (
                        array("Volvo",22,18),
                        array("BMW",15,13),
                        array("Saab",5,2),
                        array("Land Rover",17,15)
                    );

        foreach ( $data AS $row )
        {

            $finalData[] = array(
                utf8_decode( $row[0] ), // For chars with accents.
                utf8_decode( $row[1] ),
                utf8_decode( $row[2] ),
            );
        }
        foreach ( $finalData AS $finalRow )
        {
            fputcsv( $handle, $finalRow, "\t" );
        }
        fclose( $handle );
        $this->_helper->layout->disableLayout();
    $this->_helper->viewRenderer->setNoRender(TRUE);
        $this->getResponse()->setRawHeader( "Content-Type: application/vnd.ms-excel; charset=UTF-8" )
            ->setRawHeader( "Content-Disposition: attachment; filename=otros-fondos.xls" )
            ->setRawHeader( "Content-Transfer-Encoding: binary" )
            ->setRawHeader( "Expires: 0" )
            ->setRawHeader( "Cache-Control: must-revalidate, post-check=0, pre-check=0" )
            ->setRawHeader( "Pragma: public" )
            ->setRawHeader( "Content-Length: " . filesize( $filename ) )
            ->sendResponse();
        readfile( $filename ); exit();

错误: 按姓名布局找不到行动帮助

1 个答案:

答案 0 :(得分:0)

这与您的代码存在细微差别,但这是您可以尝试执行的操作:

$this->_helper->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender(true);

布局助手可能需要括号。

修改

由于看起来无法找到该插件:您确定它存在于Zend/Layout/Controller/Action/Helper/Layout.php并且正在自动加载吗?

您的application.ini有哪些内容?