douzhunlan5930 2011-06-11 10:56
浏览 15
已采纳

Zend:召唤一个动作

I'm trying to get my head around the Zend Framework.

I've created a custom route

resources.router.routes.helloworld.route = /helloworld
resources.router.routes.helloworld.defaults.module = default
resources.router.routes.helloworld.defaults.controller = helloworld
resources.router.routes.helloworld.defaults.action = display

In my hellowrold controller class I have changed the indexAction() name to displayAction().

when I try to load the page in a browser I get the following error message: 'script'xxx/display.phtml' not found in path(C:/:blah blah blah)'

What am I doing wrong here?

  • 写回答

1条回答 默认 最新

  • duanmi8349 2011-06-11 11:07
    关注

    By default Zend Framework controller actions use the ViewRenderer Controller helper. This helper reads a .phtml file related to the action as the View Script of the related action.

    The controller accesses models and in the end passes the result data to view scripts, so view scripts could present the data. This is the "V" in the "MVC" abbreviation.

    For your case, you have specified that your default action is named "display" instead of "index".

    But I think you have forgotten to create a view script file for this action. By default the view scripts are located in the APPLICATION_PATH/application/views/scripts directory, with these assumptions:

    1. APPLICATION_PATH is where your application structure and public directory reside in, (for example /var/www/ on Debain Linux or C:\Program Files\Apache Group\Apache\htdocs on Windows).
    2. You are keeping the source code of your application (including your models, controllers, modules, etc.) in the directory called application
    3. If you are having modules in your application and for example your modules are defined in application/modules; then the view/scripts directory is located in each module directory instead of the root of the application structure.

    In the above directory, each controller should have a related subdirectory, and each action have a view script file in .phtml extension.

    You should create a directory called "helloworld" in there, and then create a file named "display.phtml" in that directory, so the ViewRendere controller helper class could load it and use it as the view of this action.

    If you do not want to have a view script, you should prevent the ViewRendere helper from searching for a view script file. to do so, add this code to your action in the controller code:

    $this->_helper->viewRenderer->setNoRender(true);
    

    This code tells the view renderer action helper not to search for a view script file.

    Please not that all the above are mentioned for a default configured Zend Framework application, but could be changed by configuring your application, resources and helper objects.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥30 自适应 LMS 算法实现 FIR 最佳维纳滤波器matlab方案
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行