【问题标题】:How do I display a pages on a sub folder view in Cakephp 2,4.x?如何在 Cakephp 2,4.x 的子文件夹视图中显示页面?
【发布时间】:2014-08-21 03:05:02
【问题描述】:

是否可以在 cakephp 的视图中显示子文件夹下的页面? 这是我的文件夹结构:

<pre>
-Views
  |-Elements
  |-Emails
  |-Errors
  |-Helpers
  |-Homes
  |-Layouts
  |-Messages
  |-Pages
  |-Resources
  |-Scaffolds
   |-Tutors
    |-ManageStudents
     |-addlectures.ctp
     |-editlecture.ctp
     |-deletelecture.ctp
  |-managestudents.ctp
  |-index.ctp
  |-profile.ctp
 |-Webroots
 </pre>

现在如何显示tutors/managestudents 下的ctp 文件? 我尝试在浏览器中输入 localhost/school/tutors/managestudents/addlectures 但这不起作用。

我也尝试过使用 html 帮助链接,但还是没有成功

      $this -> html -> link ('Add lectures, array('controller' => 'tutors, 'action' =>    'ManageStudents/addlectures');

据我观察,cake 仅显示视图下的文件,但无法访问子文件夹中的文件。

【问题讨论】:

    标签: php templates cakephp


    【解决方案1】:

    首先在TutorsController.php中,你必须像ff一样渲染它:

      ...
      public function addlectures() {
        ...
        $this->render('ManageStudents/addlectures');
      }
      ....
    

    然后,您必须像这样在 app/Config 中配置 routes.php

    ...
    Router::connect('/Tutors/ManageStudents/addlectures', array('controller' => 'tutors, 'action'=> 'addlectures'));
    ..
    

    这样你可以像这样添加链接:

    $this->Html->link ('Add lectures, array('controller'=>'tutors, 'action' =>'addlectures');
    

    浏览器会像..../Tutors/ManageStudents/addlectures一样输出它

    注意:整个 Tutors 文件夹应该在 app/Views 文件夹中

    希望对你有帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-07-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-30
      • 2011-06-29
      相关资源
      最近更新 更多