gpt4 book ai didi

zend-framework - Zend rest Controller 路由到特定 Controller

转载 作者:行者123 更新时间:2023-12-01 06:51:09 28 4
gpt4 key购买 nike

我对 zend 框架相当陌生。我一直在尝试使用 Zend_Rest_Controller 编写 RESTful Controller 。我从一个很好的教程中构建了一个
http://www.techchorus.net/create-restful-applications-using-zend-framework
它完美地工作。所以我继续将它添加到现有的 zend 应用程序中。我只希望一个 Controller 是 RESTful 的,所以在 bootstrap 中进行了必要的更改。

protected function _initRestRoute()
{
$this->bootstrap('frontController');
$frontController = Zend_Controller_Front::getInstance();
$restRoute = new Zend_Rest_Route($frontController, array() , array('default' => array('MyserviceController')));
$frontController->getRouter()->addRoute('rest', $restRoute);
}

当我尝试使用 url http://localhost/projectname/public/index.php/myservice 访问服务时,服务器抛出 500 内部服务器错误它应该从 调用索引方法MyserviceController .该应用程序具有以下文件夹结构
application/
configs/
application.ini
controllers/
IndexContoller
OneController
TwoController
Myservice
forms
layouts
models
modules/
app1module
app2module
app3module
views
Bootstrap.php

这是 application.ini 为项目
[production]
phpSettings.display_startup_errors = 0
phpSettings.display_errors = 0
phpSettings.date.timezone = "America/New_York"

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

appnamespace = "Application"

resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.params.displayExceptions = 0
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts/"
includePaths.helpers = APPLICATION_PATH "/views/helpers"

;Module support
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.frontController.defaultModule = "default"
resources.modules[] = ""

resources.db.adapter = PDO_MYSQL
resources.db.params.host = ********
resources.db.params.username = *********
resources.db.params.password = *********
resources.db.params.dbname = *********

[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

这是 的代码MyserviceController.php
<?php
class MyserviceController extends Zend_Rest_Controller
{
public function init()
{
parent::init();
$this->_helper->viewRenderer->setNoRender(true);
}

public function indexAction() {
$this->getResponse()->setBody('Hello World');
$this->getResponse()->setHttpResponseCode(200);
}

public function getAction() {
$this->getResponse()->setBody('Foo!');
$this->getResponse()->setHttpResponseCode(200);
}

public function postAction() {
$this->getResponse()->setBody('resource created');
$this->getResponse()->setHttpResponseCode(200);
}

public function putAction() {
$this->getResponse()->setBody('resource updated');
$this->getResponse()->setHttpResponseCode(200);
}

public function deleteAction() {
$this->getResponse()->setBody('resource deleted');
$this->getResponse()->setHttpResponseCode(200);
}
}
?>

最佳答案

在“localhost/projectname/public/index.php/myservice”中你为什么使用 index.php ,为什么不只是 /index/ ?

ZF 的默认 URL 结构是“http://hostname/controller/action/parametes”

关于zend-framework - Zend rest Controller 路由到特定 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9439678/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com