THINKPHP 3.2.3 widget 调用模板无显示

问题描述:{:W(‘Menu/showLeftMenu’)} 无法加载Menu下面的‘menu.html

1、这里是 MenuWidget 的代码片段:

<?php
namespace Home\Controller;    
use Think\Controller;

class MenuWidget extends Controller{
   public function showLeftMenu(){
        $this->display('Menu:menu');
    }
}
?>

2、menu.html 路径:“View/Menu/menu.html”
3、menu.html 代码:

hello world!

4、主调页面路径:“View/Index/index.html”
IndexController.class.php 代码:

<?php
    namespace Home\Controller;
    use Think\Controller;

    class IndexController extends  Controller{
        $this->display();
    }
?>

index.html 代码:

<html>
    <head>
        <title>hello world!</title>
    </head>
    <body>
        {:W('Menu/showLeftMenu')}
    </body>
</html>

结果调用失败,无显示

错误分析:

其实这里的代码没有什么大的问题,主要错误的原因是:我把Widget错误的当做Controller 放在了Controller目录里面。

解决方式:

1、Menu放到与Controller同级的Widget目录中
2、将MenuWidget 里面的工作空间代码改为:namespace Home\Widget;目录即可。

<?php
namespace Home\Widget;    
use Think\Controller;

class MenuWidget extends Controller{
   public function showLeftMenu(){
        $this->display('Menu:menu');
    }
}
?>

PS:这是我用markdown在CSDN里面写的第一个总结,后期我会把我遇到的一些困难和解决方式放到这里面,就作为我的成长记录吧,也希望对遇到同样问题的小伙伴有所帮助;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
charisma国外后台模版 # Charisma ### Free, premium quality, responsive, multiple skin admin template. ##[Live Demo](http://usman.it/themes/charisma/) ### [Download](https://github.com/usmanhalalit/charisma/archive/master.zip) ##Features - 9 different themes. - Fully responsive, optimized UI for tablets and mobile phones, [see how it looks on different devices](http://www.responsinator.com/?url=usman.it%2Fthemes%2Fcharisma). - Based on Bootstrap. - Works on IE9+ - Commented code. - Custom product tour, [see example](http://usman.it/themes/charisma/tour.html). - Grid system, [see example](http://usman.it/themes/charisma/grid.html). - Charts, including, pie, stack, flot, realtime etc. - Data tables - Widget boxes, collapsible, closable, [see example](http://usman.it/themes/charisma/grid.html). - Photo gallery [see example](http://usman.it/themes/charisma/gallery.html). - Ajaxified menus - Full calendar, monthly weekly, daily, with todo list. - Custom error page - Auto active link detection and much more. ## Credits Without these open osurce software Charisma woudn't have been possible: - [Twitter Bootstrap](http://getbootstrap.com/) - [jQuery](http://jquery.com) - [Bootswatch](http://bootswatch.com/) - [Chsoen](http://harvesthq.github.com/chosen/) - [Flot Charts](http://www.flotcharts.org/) - [Full Calendar](http://arshaw.com/fullcalendar/) - [Datatables](http://datatables.net/) - [Colorbox](http://www.jacklmoore.com/colorbox/) - [Noty](http://ned.im/noty/) - [Raty](http://wbotelhos.com/raty) - iPhone-style Checkboxes - [Autogrowing Textarea](http://onehackoranother.com/projects/jquery/jquery-grab-bag/autogrow-textarea.html) - [Animate.css](http://daneden.github.io/animate.css/) - [Uploadify](http://www.uploadify.com/) Please visit [http://usman.it/free-responsive-admin-template/](http://usman.it/free-responsive-admin-template/ "") for more information. ### [Donate Charisma](http://flattr.com/thing/1507720/usmanhalalitcharisma-on-GitHub) ___ © 2012 - 2014 [Muhammad Usman](http://usman.it/). Licensed under the Apache License, Version 2.0.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值