具有自定义路由的 SocialEngine 模块

发布于 2025-01-07 14:55:30 字数 1358 浏览 1 评论 0原文

我正在为 SocialEngine 包开发一个模块,我希望能够指定多个自定义路由。

目前,我正在编辑模块目录中的 Bootstrap.php 文件,其中包含以下内容:

class Courses_Bootstrap extends Engine_Application_Bootstrap_Abstract
{
    protected function _initRouter(){
        $fc = Zend_Controller_Front::getInstance();
        $router = $fc->getRouter();
        $router->addRoute('courses', new Zend_Controller_Router_Route('courses/activity/:activity_id', array('module' => 'courses', 'controller' => 'index','action' => 'activity')));
        $router->addRoute('courses', new Zend_Controller_Router_Route('courses/course/edit/:course_id', array('module' => 'courses', 'controller' => 'course','action' => 'edit')));
        $router->addRoute('courses', new Zend_Controller_Router_Route('courses/course/create/:course_id', array('module' => 'courses', 'controller' => 'course','action' => 'create')));

        return $router;
    }

}

然而,当我指定多于 1 条路线时,所有路线都停止传递自定义变量(course_id 或 Activity_id),

我将按如下方式检索变量;

$course_id = $this->getRequest()->getParam("course_id");

我从这里采取了这种方法; http://tjgamble.com/2011/ 04/adding-custom-routes-to-your-socialengine-4-modules/

非常感谢,

安迪

I'm developing a module for the SocialEngine package and I'd like to be able to specify multiple custom routes.

Currently I'm editing the Bootstrap.php file found in the directory of my module with the following;

class Courses_Bootstrap extends Engine_Application_Bootstrap_Abstract
{
    protected function _initRouter(){
        $fc = Zend_Controller_Front::getInstance();
        $router = $fc->getRouter();
        $router->addRoute('courses', new Zend_Controller_Router_Route('courses/activity/:activity_id', array('module' => 'courses', 'controller' => 'index','action' => 'activity')));
        $router->addRoute('courses', new Zend_Controller_Router_Route('courses/course/edit/:course_id', array('module' => 'courses', 'controller' => 'course','action' => 'edit')));
        $router->addRoute('courses', new Zend_Controller_Router_Route('courses/course/create/:course_id', array('module' => 'courses', 'controller' => 'course','action' => 'create')));

        return $router;
    }

}

However it would seem that when I specify more then 1 route all routes stop passing in the custom variable (course_id or activity_id)

I'm retrieving the variable as follows;

$course_id = $this->getRequest()->getParam("course_id");

I've taken the approach from here;
http://tjgamble.com/2011/04/adding-custom-routes-to-your-socialengine-4-modules/

Many thanks,

Andy

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

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

发布评论

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

评论(1

友谊不毕业 2025-01-14 14:55:30

你必须给他们不同的名字:

    $router->addRoute('courses_activitiy', new Zend_Controller_Router_Route('courses/activity/:activity_id', array('module' => 'courses', 'controller' => 'index','action' => 'activity')));
    $router->addRoute('courses_course', new Zend_Controller_Router_Route('courses/course/edit/:course_id', array('module' => 'courses', 'controller' => 'course','action' => 'edit')));
    $router->addRoute('courses_create', new Zend_Controller_Router_Route('courses/course/create/:course_id', array('module' => 'courses', 'controller' => 'course','action' => 'create')));

you have to give them different names:

    $router->addRoute('courses_activitiy', new Zend_Controller_Router_Route('courses/activity/:activity_id', array('module' => 'courses', 'controller' => 'index','action' => 'activity')));
    $router->addRoute('courses_course', new Zend_Controller_Router_Route('courses/course/edit/:course_id', array('module' => 'courses', 'controller' => 'course','action' => 'edit')));
    $router->addRoute('courses_create', new Zend_Controller_Router_Route('courses/course/create/:course_id', array('module' => 'courses', 'controller' => 'course','action' => 'create')));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文