【问题标题】:Using Slim and not render使用 Slim 而不渲染
【发布时间】:2016-01-21 00:43:21
【问题描述】:

目前,在我的超薄框架应用程序中,我正在使用来自 Slim 视图的渲染来显示我的网站,但渲染功能没有在我的视图文件中运行 php。

查看我找到的 slim 的文档; “Slim 应用程序的 render() 方法将 echo() 从视图对象返回的输出”,这意味着 php 不会被加载,而只是在客户端打印出来。

我的问题是 slim 中是否有不同的功能来加载页面,而不是简单地在其内容被回显的地方渲染它。我需要在我的页面上运行 php,而不是简单地打印。我在下面提供了一个示例。

代码(*假设所有路由都正确):

$app->render('home.php'); //in one file

//part of home.php that is not ran because it is simply echoed out
//i want this page to be loaded, not simply echoed out
<?php
    if (isset($_SESSION['userLogin']))
    {
      echo '<form id="login" name="loginForm" method="post">
      <input class="loginForm" type="submit" value="Log In" id="submitLogin">
      <input class="loginForm" type="password" name="password" placeholder="Password" id="passLogin">
      <input class="loginForm" type="text" name="username" placeholder="Username" id="usernameLogin">
    </form>';
    }
    else
    {
      //echo 'button';
    }
?>  

【问题讨论】:

    标签: php render slim


    【解决方案1】:

    slim 框架有它自己的templates engine

    你为什么不使用这个功能?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-01-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多