开发者社区> 问答> 正文

对函数方法注入一个实例报错了...?报错

public function index(IndexModel $model){
		
	$fields = Request::getRequest('page', 'int');
    $page = isset($fields) && $fields > 0 ? $fields : 1;
    //$model= new IndexModel;
    $ret = array();
    $ret['articleList'] = $model->getArticleList($page);//var_dump($ret);exit();
	$ret['pushArticleList'] = $model->getPushArticleList();
	$ret['tagList'] = $model->getTagList();
	$ret['pushIndex'] = $model->getPushIndex();
    $ret['commentList'] = $model->getCommentList();
	View::Transmit('newindex',$ret);
			
}

这是报错:

Catchable fatal error: Argument 1 passed to app\Controller\indexController::index() must be an instance of app\Model\IndexModel, none given, called in F:\Apache24\htdocs\blog\AliceFrameWork\Route.php on line 44 and defined in F:\Apache24\htdocs\blog\app\Controller\indexController.php on line 14

使用

//$model= new IndexModel;

是不会报错,但我想直接这样不行吗

public function index(IndexModel $model){



展开
收起
爱吃鱼的程序员 2020-06-09 16:24:01 550 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    public function index(IndexModel$model){


    这样的话,你在调用这个函数前要实例化一个$model传进来啊

    $model=newModel;

    $class->index($model);

    2020-06-09 16:24:17
    赞同 展开评论 打赏
问答分类:
PHP
问答地址:
问答排行榜
最热
最新

相关电子书

更多
建立联系方法之一 立即下载
低代码开发师(初级)实战教程 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载