简体   繁体   English

SLIM框架PHP

[英]SLIM Framework PHP

$app->map('/users/posts/:id', function($id) use ($app) {

    if (!isset($_SESSION['user'])) {

        $app->redirect('/action/users/login/');
    }
    else{

        $app->render('something.php');
    }
})->via('GET', 'POST');

Hi All, im new with slim php framework. 大家好,我是苗条的php框架新手。 The problem i face now is when i pass parameter id at this url 我现在面临的问题是当我在此URL传递参数ID时

/users/posts/:id , 

i want to get the id value when im at something.php page. 我想在something.php页面上获取即时消息的id值。 How can i do that ? 我怎样才能做到这一点 ?

Thank you very much 非常感谢你

You can set data in the $app->render() method so something like this: 您可以在$app->render()方法中设置数据,如下所示:

$app->render(
    'something.php',
    array( 'id' => $id )
);

In the template you get this variable with: 在模板中,您可以通过以下方式获取此变量:

echo $this->data['id'];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM