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#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。