zend框架简单动作问题
我正在使用 Zend Server 在 Zend MVC 中创建一个 hello world 项目。一些路由是错误的。我通过 zend_tool zf.sh 创建项目创建项目,因此它本身创建了所有目录,我修改为indexController以尝试如下所示的一些操作,并且所有其他文件都会提醒相同..
<?php
class IndexController extends Zend_Controller_Action
{
public function init()
{
/* Initialize action controller here */
$this->_helper->viewRenderer->setNoRender();
}
public function indexAction()
{
// action body
$this->getResponse()->appendBody('hello from about Action');
}
public function aboutAction()
{
$this->getResponse()->appendBody('hello from about Action');
// action body
}
}
当我输入“http:/ /localhost/index.php”,它显示了来自indexAction()的正确信息;
当我输入“http://localhost/index”时,它显示页面未找到
当我输入“http://localhost/index.php/about”时,
它显示“消息:指定的控制器无效(关于)” 请求参数:
数组( '控制器' => '关于',
'行动' => '索引', '模块' => '默认', )
我希望控制器是索引,动作是关于..我该如何修复它...
我的 apache 配置中有这个。我想我可能配置错误,但我不知道在哪里。
<VirtualHost *:80>
#DocumentRoot "/usr/local/zend/apache2/htdocs"
DocumentRoot /home/testuser/projects/helloworldproject/public
<Directory "/home/testuser/projects/helloworldproject/public/">
SetEnv APPLICATION_ENV "development"
Order allow,deny
Allow from All
</Directory>
感谢您抽出时间。
i am creating a hello world project in Zend MVC with Zend Server. some how the routeing is wrong. I create the project by zend_tool zf.sh create project, so it creates all directory itself, and i modified to indexController to try some actions like below, and all other file reminds the same..
<?php
class IndexController extends Zend_Controller_Action
{
public function init()
{
/* Initialize action controller here */
$this->_helper->viewRenderer->setNoRender();
}
public function indexAction()
{
// action body
$this->getResponse()->appendBody('hello from about Action');
}
public function aboutAction()
{
$this->getResponse()->appendBody('hello from about Action');
// action body
}
}
when i enter "http://localhost/index.php", it shows the correct info from indexAction();
when i enter "http://localhost/index", it shows page not found
when i enter "http://localhost/index.php/about",
it shows " Message: Invalid controller specified (about) "
Request Parameters:
array (
'controller' => 'about',
'action' => 'index',
'module' => 'default',
)
i expect controller be index and action be about.. how can i fix it...
i have this in my apache config. i think i may have this configured wrong, but i dont know where.
<VirtualHost *:80>
#DocumentRoot "/usr/local/zend/apache2/htdocs"
DocumentRoot /home/testuser/projects/helloworldproject/public
<Directory "/home/testuser/projects/helloworldproject/public/">
SetEnv APPLICATION_ENV "development"
Order allow,deny
Allow from All
</Directory>
thanks for your time.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
localhost/index.php
应转到index
控制器和index
操作(index, index)
。localhost/index
还应该转到(index,index)
index.php/about
我希望转到(about,index )
,即about
控制器和index
操作,但我可能是错的(我没有测试这一点)。(index,about)
,您将转到localhost/index/about
您似乎已经正确定义了about操作
public function aboutAction< /code>,这样应该可以正常工作。
如果您希望能够访问 localhost/about 或 localhost/about/index,您将需要定义一个 about 控制器,如
class AboutController extends Zend_Controller_Action
就像您对IndexController< 所做的那样/代码>。
-- 编辑--
另外,请确保您的 .htaccess 至少看起来像这样:
localhost/index.php
should go to theindex
controller and theindex
action by default(index, index)
.localhost/index
should ALSO go to(index,index)
index.php/about
I would expect goes to(about,index)
, that is theabout
controller andindex
action, but I could be wrong (I didn't test this).(index,about)
you would go tolocalhost/index/about
You appear to have correctly defined the about action
public function aboutAction
, so that should work properly.If you want to be able to go to localhost/about or localhost/about/index you will need to define an about controller like
class AboutController extends Zend_Controller_Action
as you've done for theIndexController
.-- EDIT --
Also, make sure your .htaccess looks at minimum like this:
我认为这正是错误消息所说的,即您需要一个您没有的
about
控制器。在 URLhttp://localhost/index.php/about
中,about
将是您需要建立的完全独立的控制器。I think it's exactly the error message is saying, which is that you need a controller for
about
that you don't have. In the urlhttp://localhost/index.php/about
,about
would be a completely separate controller that you'd need to establish.