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 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)