Symfony 2,传递变量

发布于 2024-12-20 13:23:59 字数 367 浏览 3 评论 0原文

那么如何将变量传递到未与 symfony 连接的脚本中呢? 例如,我有变量 $a,我在模板 a.html.php 中渲染它 如何在某些 example.php 脚本中使用此 $a

更接近:我想用TinyMCE图像管理器进行图像上传;但每个用户应该有自己的目录(对应于用户id)。所以我应该将变量 user_id 传递到图像管理器的 config.php 文件。

所以这个目录取决于用户的会话!如何为每个用户制作不同的目录来上传图像?或者你能告诉我如何处理这个问题吗?

也许使用另一个文本编辑器?我可以使用哪一个与 symfony 连接或为不同的用户使用不同的目录?

So how can I pass a variable into a script that is not connected with symfony?
For example, I have variable $a, which I render in template a.html.php
How can I use this $a in some example.php script?

More close: I wanna make image uploading with TinyMCE image manager; but each user should have their own directory (which corresponds to user id). So I should pass variable user_id to config.php file of image manager.

So this directory depends on the user's session! How can I make different dirs to upload images for each user? Or can you advise me how to deal with this problem?

Maybe to use another text editor? Which one can I connect with symfony or to use different directories for different users?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

丢了幸福的猪 2024-12-27 13:23:59

如果您想与其他脚本共享信息,您可以将信息存储在会话中。在 example.php 中创建一个 var_dump($_SESSION) 来查看您已经拥有的内容。

You can store information in the session if you want to share it with other scripts. Make a var_dump($_SESSION) in example.php to see what you already have.

<逆流佳人身旁 2024-12-27 13:23:59
$formPath = 'nameBundle:name:name.html.twig';
            $session = $controler->getRequest()->getSession();
            $session->set('formPath', $formPath);
            $session->set('neededVariables', $neededVariables);
return $controler->redirect($controler->generateUrl('show_result'));

我用这个来处理数据和读取数据函数

public function showResultAction() {
    $session = $this->getRequest()->getSession();
    $formPath = $session->get('formPath');
    $neededVariables = $session->get('neededVariables');
    if ($formPath or $neededVariables)
        return $this->render($formPath,$neededVariables); else
        throw $this->createNotFoundException('The product does not exist');
}
$formPath = 'nameBundle:name:name.html.twig';
            $session = $controler->getRequest()->getSession();
            $session->set('formPath', $formPath);
            $session->set('neededVariables', $neededVariables);
return $controler->redirect($controler->generateUrl('show_result'));

I used this to handle data and read data function

public function showResultAction() {
    $session = $this->getRequest()->getSession();
    $formPath = $session->get('formPath');
    $neededVariables = $session->get('neededVariables');
    if ($formPath or $neededVariables)
        return $this->render($formPath,$neededVariables); else
        throw $this->createNotFoundException('The product does not exist');
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文