dsdtszi0520538 2019-05-11 18:03 采纳率: 100%
浏览 46
已采纳

在Codeigniter上的Controller中返回(退出)(提前终止)(使用Twig模板引擎)

I was told that if I write a return in the controller, it will loop and cause an error on Codeigniter.

For example, is it inappropriate to write(return view) as follows in Controller?

public function example {
    // ...
    if (some conditions ...) {
        return $this->twig->display('templates/error.html');
    }

    return $this->twig->display('templates/success.html');
}

I'm not familiar with Codeigniter.
I considered the return value to be a problem in Controller and corrected it as follows.

public function example {
    // ...
    if (some conditions ...) {
        $this->twig->display('templates/error.html');
        return;
    }

    $this->twig->display('templates/success.html');
    return;
}

The older version of Codeigniter may also be affecting... (Codeigniter 2.1.3 and PHP 5.3.3 and Twig 1.36.* )
Those who mention the location of the error are not sure about it. Errors rarely occur(ERR_EMPTY_RESPONSE).

What I want to check is if there is no problem with the above-mentioned writing method in Controller.

  • 写回答

1条回答 默认 最新

  • douou9094747 2019-05-11 19:37
    关注

    I assume by inappropriate you mean "will it cause errors" and the answer is no. The error those users are experiencing is usually due to connection issues on their end, or a server issue unrelated to php.

    CodeIgniter in their docs even uses controller methods with return statements as a means for form validation callbacks, so it isn't unheard of.

    That being said, I'm not entirely sure why you even need these return statements. exit() would be more appropriate if you wanted to the script to stop.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改