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

    评论

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测