1

伙计们,我的项目中有以下结构。

application/
   Bootstrap.php
   configs/
      application.ini
   modules/
      default/
         controllers/
         models/
         views/
         Bootstrap.php
      main/
         controllers/
            UserController.php
         forms/
         models/
            resources/
            validate/
         views/
            scripts/
               user/
                  complete-registration.phtml
                  index.phtml
                  register.phtml   
         Bootstrap.php
      rest/
         controllers/
            LoginController.php
         models/
         views/
         Bootstrap.php

现在来解决问题。我在 UserController.php 中定义了一些我似乎无法访问的操作。例如,如果我去 localhost/main/user/register 我无法访问它。但是我浏览到 localhost/main/user 它可以工作。

我不知道它可能是什么,但我的疯狂猜测是它与我的 Bootstrap.php 有关。在调试时,我在主 bootstrap.php 中注释了其余路由初始化,它似乎有效。我已经给出了我认为受此影响的所有文件。如果我能知道它可能是什么,那就太棒了。已经花了几天时间试图弄清楚这一点。

引导程序.php

<?php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
    // Commenting this seems to make the module auto initializing work.
    protected function _initRestRoute()
    {
        $this->_logger->info('Bootstrap ' . __METHOD__);
        $this->bootstrap ( 'frontController' );
        $frontController = Zend_Controller_Front::getInstance ();
        //$restRoute = new Zend_Rest_Route ( $frontController );
        //$frontController->getRouter ()->addRoute ( 'default', $restRoute );
        $restRoute = new Zend_Rest_Route($frontController, array(), array('rest'));
        $frontController->getRouter ()->addRoute('rest', $restRoute);
    }
}

主/引导程序.php

<?php

class Main_Bootstrap extends Zend_Application_Module_Bootstrap
{

}

主/控制器/UserController.php

<?php

class Main_UserController extends Zend_Controller_Action
{

    protected $_model;

    public function init()
    {
        // Get the default model
        $this->_model = new Main_Model_User ();
        // Add forms
        $this->view->registerForm = $this->getRegistrationForm ();
    }

    public function indexAction()
    {
    }

    public function registerAction()
    {
    }

    public function completeRegistrationAction()
    {
        $request = $this->getRequest ();
        if (! $request->isPost ())
        {
            return $this->_helper->redirector ( 'register' );
        }
        if (false === $this->_model->registerUser ( $request->getPost () ))
        {
            return $this->render ( 'register' );
        }
    }

    public function getRegistrationForm()
    {
        $urlHelper = $this->_helper->getHelper ( 'url' );
        $this->_forms ['register'] = $this->_model->getForm ( 'userRegister' );
        $this->_forms ['register']->setAction ( $urlHelper->url ( 
            array (
                'controller' => 'user', 
                'action' => 'complete-registration' 
            ), 
            'default' ) );
        $this->_forms ['register']->setMethod ( 'post' );
        return $this->_forms ['register'];
    }
}

应用程序.ini

[production]
autoloadernamespaces[] = "Zend_"
autoloadernamespaces[] = "SB_"

phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1

includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
appnamespace = "Application"

; front controller
resources.frontcontroller.moduledirectory = APPLICATION_PATH "/modules"

; modules
resources.modules[] =

resources.frontController.params.displayExceptions = 1

resources.db.adapter = "PDO_MYSQL"
resources.db.isdefaulttableadapter = true
resources.db.params.dbname = "****"
resources.db.params.username = "*****"
resources.db.params.password = "*******"
resources.db.params.host = "*******"
resources.db.params.charset = "UTF8"

[staging : production]

[testing : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1

[development : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
resources.frontController.params.displayExceptions = 1
4

3 回答 3

1

通过执行以下操作设法使其工作。希望这对某人有用。

在前端控制器插件中创建了一个路由。

class SB_Controller_Plugin_Initialize extends Zend_Controller_Plugin_Abstract
{

    public function routeStartup(Zend_Controller_Request_Abstract $request)
    {
        $frontController = Zend_Controller_Front::getInstance();
        $restRoute = new Zend_Rest_Route($frontController, array(), array('rest'));
        $router = $frontController->getRouter();
        $router->addRoute('rest', $restRoute);
    }
}

在 application.ini 中,

resources.frontController.plugins.Initialize = "SB_Controller_Plugin_Initialize"
于 2010-11-07T01:43:54.940 回答
1

在主引导程序中添加它

protected function _initRoutes()
    {
        $front = Zend_Controller_Front::getInstance();
        $router=$front->getRouter();
        $restRoute=new Zend_Rest_Route($front,array(),array('yourrestmodule'));
        $router->addRoute('yourrestmodule',$restRoute);
    }
于 2013-04-03T07:14:02.267 回答
0

也许在下一个解决方案:
1)你的registerAction存在吗?
2)你的view这个动作是存在的吗?/views/scripts/user/register.phtml

于 2010-11-04T08:12:15.307 回答