简体   繁体   English

Zend Framework 1.12-动作控制器无法正常工作

[英]Zend Framework 1.12 - Action Controller not working

I am new to Zend framework and I have installed zend frameworkd 1.12. 我是Zend框架的新手,并且已安装zend frameworkd 1.12。 It seems to be running find except for the fact the the views don't read the command specify in the action controller. 除了视图不读取动作控制器中指定的命令外,它似乎正在运行find。

I have tested this with two controllers one is the index controller and second a created controller through zf command. 我已经用两个控制器测试了它,一个是索引控制器,另一个是通过zf命令创建的控制器。 here is the code. 这是代码。

<?php

class TestController extends Zend_Controller_Action
{

    public function init()
    {
        /* Initialize action controller here */
        //echo "Please read this";
    }

    public function indexAction()
    {
        echo 1;
    }

}

Here is the link to the view for this controller (just to be sure that not the problem) 这是此控制器视图的链接(请确保不是问题)

Zend_Projects/test1/application/views/scripts/test/index.phtml Zend_Projects / test1 / application / views / scripts / test / index.phtml

and the output of the controller: 以及控制器的输出:

-->> View script for controller Test and script/action name index ->>查看控制器测试和脚本/动作名称索引的脚本

It does not add the 1 or any string from the echo command 它不会在echo命令中添加1或任何字符串

Can anyone tell me why the controller action is not be read by the view? 谁能告诉我为什么视图不读取控制器动作?

Please any sort of help is appreciated and I apologize in advance if this is a stupid question. 请提供任何帮助,如果这是一个愚蠢的问题,我提前致歉。

Best of Regards 最好的问候

If you want to output an value from your Action inside your view, you have to to pass it with: 如果要在视图内从Action输出值,则必须使用以下命令传递该值:

public function indexAction()
{
   $this->view->mytext = 'Test';
}

now inside your .phtml script: 现在在您的.phtml脚本中:

<?php echo $this->mytext; ?> 

As per the comments to the question 根据对问题的评论

You dont have to copy anything php file to public folder except for index.php also make sure there is a .htaccess file present in public folder and mod_rewrite is enabled in apache. 您无需将任何php文件复制到公用文件夹(除ind​​ex.php之外),还请确保公用文件夹中存在.htaccess文件,并且在apache中启用了mod_rewrite。 That is if you are using apache (otherwise you should use url rewriting method of the server that you are using.) If this all sounds greek to you and I assume you dont know greek then refer http://framework.zend.com/manual/1.12/en/zend.controller.router.html 就是说,如果您使用的是Apache(否则,您应该使用所用服务器的url重写方法。)如果这一切听起来对您来说希腊语,并且我认为您不知道希腊语,请访问http://framework.zend.com/手册/1.12/zh/zend.controller.router.html

if all this is already done then there might be a problem with router. 如果所有这些都已经完成,那么路由器可能有问题。 refer http://framework.zend.com/manual/1.12/en/project-structure.rewrite.html 请参阅http://framework.zend.com/manual/1.12/en/project-structure.rewrite.html

The key is that you dont call the actual phtml file in a browser, that is done by the application. 关键是您不要在浏览器中调用实际的phtml文件,而是由应用程序完成的。 The browser always calls index.php in public folder which is done via rewriting urls. 浏览器始终通过重写URL来调用公用文件夹中的index.php。 the index.php file initializes the zend application and runs it. index.php文件将初始化zend应用程序并运行它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM