doushouxie7064 2012-11-29 01:47
浏览 33
已采纳

Zend框架,View

Small mystery: can't seem to pass views between my Index controller (chartAction) and my view. When I go to my localhost it is not accessing the view phtml- instead it is just showing the controller every time (i.e: if I write "echo "HELLO WORLD!""; in my controller I get that echoed...but if I do a $this->view->test = "Hello World!" then access the index.phtml and type in echo $this->test; I get nothing (it still defaults to the controller action). Is there a step that I'm missing here? Why is my $this->view not functioning? I used the command line to create the view so I'm pretty sure that should be set up correctly. Do I need to register something? Thanks for any help!

  • 写回答

3条回答 默认 最新

  • dpjo15650 2012-11-29 07:27
    关注

    Assuming a standard MVC setup of ZF1.x, there is a definite relationship between the url, the controller and the action.

    The url http://mydomain.com/index would call the index action of the index controller, typically the index action is the default action and is called automatically. the view script would be /application/views/scripts/index/index.phtml

    The url http://mydomain.com/index/chart would call the chart action of the index controller and the view script would be /application/views/scripts/index/chart.phtml

    Keep in mind that this behavior is changeable based on configuration and routing options.

    It sounds like you may be fairly new at working with ZF. So something like the following may help demonstrate the relationship :

    // application/controllers/IndexController.php
    class IndexController extends Zend_Controller_Action
    {
        public function init()
        {
    
        }
    
        public function indexAction()
        {
            $this->view->test = "Hello World, from the indexAction().";
        }
        public function chartAction()
        {
            $this->view->test = "Hello World, from the chartAction().";
        }
    
    
    // application/views/scripts/index/index.phtml
    <?php echo $this->test ?>
    
    
    // application/views/scripts/index/chart.phtml
    <?php echo $this->test ?>
    

    now test your application by calling the url's:

    http://yourDomain.com/index/index
    http://yourDomain.com/index/chart

    If your setup is correct you will see the proper response in your pages.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作