我如何引用此响应中发送的任何内容?

How do i reference whatever content is being sent in this response?

在我进入这家公司之前很久,我目前正在使用一个基于 symfony 1.4 构建的系统。

我正在尝试修改一个强制 excel 下载的功能,但我无法弄清楚内容的设置位置。我的假设是它以某种方式抓住了整个“$this”object?

我看到了 headers:

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

我看到这个函数被调用了:

$this->setLayout('none');

其他所有内容都是传递给视图的变量。

我只需要能够引用发送下载的内容,这样我就可以通过 PHPExcel 运行 它。

知道如何引用发送的内容吗?

更新:这是整个函数

$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');

我想出来了,答案如下...

这就是我能够引用发送到视图的信息的方式:

$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);

希望这能对某人有所帮助。谢谢!