首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何修复这个php错误“警告"?

如何修复这个php错误“警告"?
EN

Stack Overflow用户
提问于 2016-05-31 06:57:34
回答 2查看 1.6K关注 0票数 1

大家好,我有这个codeigniter代码,模型是:

代码语言:javascript
复制
<?php

 class Product extends CI_Model{
  var $title;
  var $price;
  var $name=" "; 
  public function __construct($title1,$price1,$name1)  
  {
    parent::__construct();
    $this->load->database();
    $this->title=$title1;
    $this->price=$price1;
    $this->name=$name1;
  }
  function set_Name ($newname)
  {
    $this->name=$newname;
  }
  function get_Nmae()
  {
    return $this->name;
  }
  function set_title($newtitle){
    $this->title=$newtitle;
  }

   function set_price($newprice) {
    $this->price=$newprice;
 }
 function get_productAttribute (){
  $x1=$this->name;
  $x2=$this->title;
  $x3=$this->price;
  $productattribute  = array( "$x1","$x2","$x3" );
  return $productattribute ;

 }
 public function get_data(){
  $query=$this->db->query('SELECT*FROM Saied');
  return $query->row_array();
 }
  public function insert_indb($var){
  if (is_a($var, 'Furniture'))
  {   
$data= array(
    'id1' => '',
    'name1'=> $this->title,
    'title1' => $this->title,
    'price1' => $this->price, 
    'size1' => $this->size,  
    'material1'=>$this->material

    );
  $this->db->insert('Furn',$data);
  return $data;

 }
 elseif (is_a($var, 'CDDVD'))
 {
  $data1= array(
  'id' => '',
  'title'=>$this->title,
  'price'=>$this->price,
  'name'=>$this->name,
  'sizemb'=>$this->sizeinmb."MB",
  'manufacture'=>$this->manufacturer
   );
  return $data1;
 }
 else 
 {
  echo "no spicifed objech";
 }
}
}
 class Furniture extends Product
{
  var $size;
  var $material;
 public function __construct($title1,$price1,$name1,$sizeset,$materialset)
  {
    $this->size=$sizeset;
    $this->material=$materialset;
    parent::__construct($title1,$price1,$name1);
    $this->name1=" ";
  }
 public function setAtribute_Furniture ($size1,$material1)
  {
    $this->size=$size1;
    $this->material=$material1;
  }
}
 class CDDVD extends Product 
{
  var $sizeinmb;
  var $manufacturer;
  public function __construct($title1,$price1,$name1,$sizeinmbset,$manufacturerset)
  {
    $this->sizeinmb=$sizeinmbset;
    $this->manufacturer=$manufacturerset;
    parent::__construct($title1,$price1,$name1);
  }
  public function setAttribute_CDVD ($sizeinmb1,$manufacturer1)
  {
    $this->sizeinmb=$sizeinmb1."MB";
    $this->manufacturer=$manufacturer1;
  }  
}
$chair = new Furniture("ilove","200 euro"," ","200x200 ","wood");

print_r($chair->insert_indb($chair));

?>

加载此模型的控制器为:

代码语言:javascript
复制
 public function __construct()
      {
        parent::__construct();
        $this->load->model('product');
      }


      }

事情就是每件事都按照我想要的方式工作,我插入到数据库中,并为每个类打印数组或数组1中的值,但是协作者给我一个流动的错误/警告:遇到一个PHP错误

代码语言:javascript
复制
Severity: Warning

Message: Missing argument 1 for Product::__construct(), called in /Applications/MAMP/htdocs/SandWeb/system/core/Loader.php on line 353 and defined

Filename: models/Product.php

Line Number: 7

Backtrace:

File: /Applications/MAMP/htdocs/SandWeb/application/models/Product.php
Line: 7
Function: _error_handler

File: /Applications/MAMP/htdocs/SandWeb/application/controllers/Pages.php
Line: 80
Function: model

File: /Applications/MAMP/htdocs/SandWeb/index.php
Line: 315
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: Missing argument 2 for Product::__construct(), called in /Applications/MAMP/htdocs/SandWeb/system/core/Loader.php on line 353 and defined

Filename: models/Product.php

Line Number: 7

Backtrace:

File: /Applications/MAMP/htdocs/SandWeb/application/models/Product.php
Line: 7
Function: _error_handler

File: /Applications/MAMP/htdocs/SandWeb/application/controllers/Pages.php
Line: 80
Function: model

File: /Applications/MAMP/htdocs/SandWeb/index.php
Line: 315
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: Missing argument 3 for Product::__construct(), called in /Applications/MAMP/htdocs/SandWeb/system/core/Loader.php on line 353 and defined

Filename: models/Product.php

Line Number: 7

Backtrace:

File: /Applications/MAMP/htdocs/SandWeb/application/models/Product.php
Line: 7
Function: _error_handler

File: /Applications/MAMP/htdocs/SandWeb/application/controllers/Pages.php
Line: 80
Function: model

File: /Applications/MAMP/htdocs/SandWeb/index.php
Line: 315
Function: require_once

A PHP Error was encountered

Severity: Notice

Message: Undefined variable: title1

Filename: models/Product.php

Line Number: 11

Backtrace:

File: /Applications/MAMP/htdocs/SandWeb/application/models/Product.php
Line: 11
Function: _error_handler

File: /Applications/MAMP/htdocs/SandWeb/application/controllers/Pages.php
Line: 80
Function: model

File: /Applications/MAMP/htdocs/SandWeb/index.php
Line: 315
Function: require_once

A PHP Error was encountered

Severity: Notice

Message: Undefined variable: price1

Filename: models/Product.php

Line Number: 12

Backtrace:

File: /Applications/MAMP/htdocs/SandWeb/application/models/Product.php
Line: 12
Function: _error_handler

File: /Applications/MAMP/htdocs/SandWeb/application/controllers/Pages.php
Line: 80
Function: model

File: /Applications/MAMP/htdocs/SandWeb/index.php
Line: 315
Function: require_once

A PHP Error was encountered

Severity: Notice

Message: Undefined variable: name1

Filename: models/Product.php

Line Number: 13

Backtrace:

File: /Applications/MAMP/htdocs/SandWeb/application/models/Product.php
Line: 13
Function: _error_handler

File: /Applications/MAMP/htdocs/SandWeb/application/controllers/Pages.php
Line: 80
Function: model

File: /Applications/MAMP/htdocs/SandWeb/index.php
Line: 315
Function: require_once

因此,我的问题是,我如何忽略这些警告,或者可能我以错误的方式加载模型。?

EN

回答 2

Stack Overflow用户

发布于 2016-05-31 10:43:27

出现此错误是因为CI模型的构造函数不能接收参数。请参阅CI的模型加载器的源代码,该程序位于名为model的方法的/YourCIAPP/system/Core/Loader.php

在该方法的底部,您可以看到CI加载模型,其中包含以下代码

代码语言:javascript
复制
require_once($mod_path.'models/'.$path.$model.'.php');
$this->_ci_models[] = $name;
$CI->$name = new $model();

看,CI只是一个新的模型对象,没有给模型类的构造函数带参数。

票数 0
EN

Stack Overflow用户

发布于 2019-10-02 22:22:21

只有两种可能:路径错误,或者权限错误。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37534570

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档