有关MVC多层设计,实例化对象的问题

浏览:919 发布日期:2015/06/25 分类:求助交流 关键字: MVC多层设计 Service实例化方法无法访问
今天看了一些 有关TP MVC 多层设计的内容。(多层设计详细内容见http://www.thinkphp.cn/info/65.html)。闲暇无事做一个Demo尝试一下。问题即出现。就是在实例化Service的对象后,无法调用其对象自定义方法。通过排查好像是应为D方法返回的是Model对象,而非Service对象。郁闷!下面为关键代码。namespace Admin\Service;
use Think\Model;


class serviceinfoService  extends Model
{
   
 

    function __construct()
    {
       parent::__construct();
    }


    public function showMessage($value='')
    {
        echo "this is showMessage function";
        # code...
    }



}
Controller 语句namespace Admin\Controller;
use Think\Controller;
class TestController extends Controller {

    public function index(){
        header('Content-type:text/html;charset=UTF-8');

       // $datetime1 = date('2015-05-29 00:00:00');
       // $datetime2 = date('2015-05-30 00:00:00');
       // $interval = date_diff($datetime1, $datetime2);
       // echo strtotime($datetime1);
       //  echo  DateDiff('d',$datetime1,$datetime2);
       //
       //serviceinfoService

       $serviceinfoServiceObj=D('serviceinfo','Service');
       $serviceinfoServiceObj->showMessage();
       
    }

}
:(
Think\Model:showMessage方法不存在!
错误位置

FILE: F:\PHP_Project\www\workFlowProject_Update\ThinkPHP\Library\Think\Model.class.php  LINE: 241
TRACE

#0 F:\PHP_Project\www\workFlowProject_Update\ThinkPHP\Library\Think\Model.class.php(241): E('Think\Model:sho...')
#1 F:\PHP_Project\www\workFlowProject_Update\App\Admin\Controller\TestController.class.php(26): Think\Model->__call('showMessage', Array)
#2 F:\PHP_Project\www\workFlowProject_Update\App\Admin\Controller\TestController.class.php(26): Think\Model->showMessage()
#3 [internal function]: Admin\Controller\TestController->index()
#4 F:\PHP_Project\www\workFlowProject_Update\ThinkPHP\Library\Think\App.class.php(164): ReflectionMethod->invoke(Object(Admin\Controller\TestController))
#5 F:\PHP_Project\www\workFlowProject_Update\ThinkPHP\Library\Think\App.class.php(202): Think\App::exec()
#6 F:\PHP_Project\www\workFlowProject_Update\ThinkPHP\Library\Think\Think.class.php(120): Think\App::run()
#7 F:\PHP_Project\www\workFlowProject_Update\ThinkPHP\ThinkPHP.php(97): Think\Think::start()
#8 F:\PHP_Project\www\workFlowProject_Update\index.php(15): require('F:\PHP_Project\...')
#9 {main}

ThinkPHP3.2.3 { Fast & Simple OOP PHP Framework } -- [ WE CAN DO IT JUST THINK ]
使用的TP的版本为3.2.3 。还请哪位大侠 帮忙看看
最佳答案
评论( 相关
后面还有条评论,点击查看>>