关于 symfony 中的操作

发布于 2024-10-10 05:11:51 字数 742 浏览 2 评论 0原文

在我的网站上,我有一个小组部分。这些组有活动、论坛等。我使用 symfony 并且有以下文件:

class GroupActions extends sfActions{


public function preExecute(){

   $request = $this->context->getRequest();


   $this->group = fGroup::getGroupById($request->getRequestParameter('id_group'));

   //Group security

   $this->group_security = $this->group->getSecurity();

   //More required actions about groups

   ....


}



class ForumActions extends GroupActions {


public function preExecute() {


    parent::preEcecute();

    $this->forum = $this->group->getForums();


}

ForumActions 扩展了 GroupActions 因为我需要组数据。例如,请求:

/groups/2/forum

转发到ForumActions,我可以获取组的数据。

这是正确的吗?

谢谢。

In my website I have a section of groups. The groups have events, forum, etc. I use symfony and I have the following files:

class GroupActions extends sfActions{


public function preExecute(){

   $request = $this->context->getRequest();


   $this->group = fGroup::getGroupById($request->getRequestParameter('id_group'));

   //Group security

   $this->group_security = $this->group->getSecurity();

   //More required actions about groups

   ....


}



class ForumActions extends GroupActions {


public function preExecute() {


    parent::preEcecute();

    $this->forum = $this->group->getForums();


}

ForumActions extends GroupActions because I need group data. For example, the request:

/groups/2/forum

forwards to ForumActions and I can get group's data.

Is this correct?

Thanks.

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

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

发布评论

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

评论(1

仲春光 2024-10-17 05:11:51

在这里,我认为这里有一个错误:

$this->group = fGroup::getGroupById($request->getRequestParameter('id_group'));

它应该是:

$this->group = fGroup::getGroupById($request->getParameter('id_group'));

也许这就是你最终得到一个空的组信息的方式。另外,在操作中定义类变量,然后在某种方法中初始化它们(getter 和 setter 也可以提供帮助)始终是一种惯例,这样您就可以确保其他可能需要它们的变量可以被访问。

Here there, i think there is a mistake here where it says:

$this->group = fGroup::getGroupById($request->getRequestParameter('id_group'));

And it should be:

$this->group = fGroup::getGroupById($request->getParameter('id_group'));

Maybe that is way you ended up with an empty group info. Also, its always a got practice to define your class variables in the action and then initialize them in some method (also getters and setters could help.) so you assure that variables could be reached be others that might need them.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文