dpowt82802 2018-11-13 16:03
浏览 260

当使用模型渲染视图时,Yii2显示空白页面

i'm new working with yii,

maybe is just a estupid thing but a can't make it work,

i have this:

$turno = new Turnosservice();
$turno->turno_id = $this->request->get('d');
$turno->disponibilidad_id = $this->request->get('t');
$turno->hash = trim($this->request->get('session'));
$turno->operacion = 'C';
$turno->plataform = $this->getPlatform($this->request->userAgent);
$turno->appversion = $this->request->userAgent;
$turno->appname = $this->getBrowser($this->request->userAgent);
$turno->estado = 0;
$turno->host = $this->request->userIP;

//var_dump($turno);

return $this->render('anulacion', ['model' => $turno]);

everything looks good, the model have all the data needed, but when render, just shows a blank page,

but if i do this:

return $this->render('anulacion', ['model' => $model = new Turnosservice()]);

of course, this last just load a empty model without the data i need.

  • 写回答

1条回答 默认 最新

  • doumizhi0809 2018-11-14 14:43
    关注

    thanks for your answers, i already solved this.

    for anyone in the same situation:

    the problem was...

    i have an Action called:

     public function actionIndex()
    {... }
    

    and inside the action i called a function that process the data. but my mistake was:

    the function process (the function that process the data) do:

    private function process()
    {
     .... 
        return $this->render('anulacion', ['model' => $turno]); 
    }
    

    the problem here is that the Function Action should return the render, not the other function, the action always return the render (if you want to show something)

    finally i changed the function action to return the render

    public function actionIndex
    {
      ...
      return $this->render('view', ['model'=>$model]); 
    }
    

    and that it.

    i hope this would be helpfull to others,

    PS sorry by my english

    评论

报告相同问题?

悬赏问题

  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容