2016-08-09 1 views
-1

私は現在、この会社に入社する前からsymfony 1.4で構築されたシステムで作業しています。このレスポンスで送信されているコンテンツはどのように参照しますか?

Excelを強制的にダウンロードする機能を変更しようとしていますが、コンテンツがどこに設定されているのかわかりません。私の前提は、 '$ this'オブジェクトの全体を何らかの形で取得していることです。

私は、ヘッダーを参照してください。

$this->getResponse()->setHttpHeader('Content-Disposition', 'filename=winners.xls'); 
$this->getResponse()->setHttpHeader('Content-Type', 'application/vnd.ms-excel; charset=utf-8'); 

を、私は、この関数が呼び出されている参照してください。

$this->setLayout('none'); 

と他のすべてのビューに渡される変数です。

PHPExcelで実行できるように、ダウンロードするコンテンツを参照できるだけでいいです。

送信されるコンテンツの参照方法はありますか?

UPDATE:ここでは全体の機能は、これは私が送信された情報を参照することができた方法です...

私はこれを理解することができた、と次のように答えがある

$round = $request->getParameter("round"); 
$league = $request->getParameter("league"); 

$this->all_contest_ids = array(); 
$contest = asPickem::getInstance()->getContest(); 

// find all child contest ids 
$this->all_contest_ids[] = $contest->getId(); 
if ($contest->getNode()->hasChildren()) { 
    foreach ($contest->getNode()->getDescendants() as $child) { 
    $this->all_contest_ids[] = $child->getId(); 
    } 
} 


if (!$round || $round == "-1") { 
    $tablename = ucfirst(asPickem::getInstance()->getProduct()->getSlug()) . 'RankUserOverall'; 
    $query = Doctrine_Core::getTable($tablename)->getRankingsQuery(asPickem::getInstance()->getContest()->getId(), $this->getExcludedUserEntryIds()); 
    $this->title = "Overall Rankings"; 
} // show round results 
else { 

    if (isset($league)) { 
    $tablename = ucfirst(asPickem::getInstance()->getProduct()->getSlug()) . 'RankLeagueUser'; 
    $query = Doctrine_Core::getTable($tablename)->getRankingsQuery($league, $round); 

    } else { 
    $tablename = ucfirst(asPickem::getInstance()->getProduct()->getSlug()) . 'RankUser'; 
    $query = Doctrine_Core::getTable($tablename)->getRankingsQuery(asPickem::getInstance()->getContest()->getId(), $round, $this->getExcludedUserEntryIds($this->round)); 

    } 


    $r = Doctrine_Core::getTable('CampaignRound')->find($round); 

    $this->title = $r->getView() . " Rankings"; 
} 

$limit = $request->getParameter("limit", 100); 
if ($limit > 0) { 
    $query->limit($limit); 
} 

$this->rankings = $query->execute(); 

// load survey questions 
$survies = array(); 
$thisSurvies = Doctrine_Core::getTable('Survey')->getByContest(asPickem::getInstance()->getContest()->getId()); 

foreach ($thisSurvies as $survey) { 
    $survies[] = $survey; 
} 

// if this contest is a child of a portal then include the parent surveys 
$c = asPickem::getInstance()->getContest(); 
while ($c->getParent()) { 
    $c = $c->getParent(); 

    if ($c->getProduct()->getSlug() == 'portal') { 
    $this->includeParentSurveyQuestions = true; 
    break; 
    } 
} 


if ($this->includeParentSurveyQuestions) { 
    $contest = asPickem::getInstance()->getContest(); 
    while ($contest->getParent()) { 
    $contest = $contest->getParent(); 
    $parentSurvies = Doctrine_Core::getTable('Survey')->getByContest($contest->getId()); 

    foreach ($parentSurvies as $survey) { 
     $survies[] = $survey; 
    } 
    } 
} 

$this->questions = array(); 
foreach ($survies as $survey) { 
    foreach ($survey->getSortedQuestions() as $question) { 
    $this->questions[$question->getId()] = $question->getQuestionText(); 
    } 
} 
unset($survies); 

$temp = tempnam(sys_get_temp_dir(), 'html'); 
file_put_contents($temp, $this->getResponse()->getTemplate()); 

//build instance of PHPExcel object, and load/read html file 
require_once dirname(__FILE__) . '/../../../../../EXCEL/PHPExcel.php'; 
$objPHPExcel = new PHPExcel(); 
$excelHTMLReader = PHPExcel_IOFactory::createReader('HTML'); 
$excelHTMLReader->loadIntoExisting($temp, $objPHPExcel); 
$objPHPExcel->getActiveSheet()->setTitle('userlist'); 

//delete the temporary file 
unlink($temp); 

$this->getResponse()->setHttpHeader('Content-Disposition', 'filename=winners.xls'); 
$this->getResponse()->setHttpHeader('Content-Type', 'application/vnd.ms-excel; charset=utf-8'); 

$writer = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); 
$this->renderText($writer->save('php://output')); 

$this->setLayout('none'); 

答えて

0

ですビューへ:同様の問題に直面して終わる可能性が人のために

$this->setLayout('none'); 
$view = $this->getController()->getView($this->getContext()->getModuleName(), $this->getContext()->getActionName(), sfview::SUCCESS); 
$view->execute(); 
$view->getAttributeHolder()->add($this->getVarHolder()->getAll()); 
$exContent = $view->render(); 

、ここで私は参照を取得し、順番にPHPExcelを通してそれを実行するために使用されるものの全体を見ていますファイルに関するExcelの警告ポップアップを停止するには:

$this->setLayout('none'); 
$view = $this->getController()->getView($this->getContext()->getModuleName(), $this->getContext()->getActionName(), sfview::SUCCESS); 
$view->execute(); 
$view->getAttributeHolder()->add($this->getVarHolder()->getAll()); 
$exContent = $view->render(); 

$temp = tempnam(sys_get_temp_dir(), 'html'); 
file_put_contents($temp, $exContent); 

//build instance of PHPExcel object, and load/read html file 
require_once dirname(__FILE__) . '/../../../../../EXCEL/PHPExcel.php'; 
$objPHPExcel = new PHPExcel(); 
$excelHTMLReader = PHPExcel_IOFactory::createReader('HTML'); 
$excelHTMLReader->loadIntoExisting($temp, $objPHPExcel); 
$objPHPExcel->getActiveSheet()->setTitle('userlist'); 

//delete the temporary file 
unlink($temp); 

header('Content-Type: application/vnd.ms-excel'); // header for .xls file 
header('Content-Disposition: attachment;filename=winners.xls'); // specify the download file name 
header('Cache-Control: max-age=0'); 

$writer = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); 
$writer->save('php://output'); 

$this->setLayout(false); 

これは誰かを助けることができますか?ありがとう!

関連する問題