Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/297.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
“如何修复此php错误”;警告;?_Php_Codeigniter - Fatal编程技术网

“如何修复此php错误”;警告;?

“如何修复此php错误”;警告;?,php,codeigniter,Php,Codeigniter,大家好,我有一个codeigniter代码模型是: <?php class Product extends CI_Model{ var $title; var $price; var $name=" "; public function __construct($title1,$price1,$name1) { parent::__construct(); $this->load->database(); $this->

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

<?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));

?>
 public function __construct()
      {
        parent::__construct();
        $this->load->model('product');
      }


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

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

所以我的问题是,我怎么能忽略这些警告,或者我可能是以错误的方式加载模型

由于CI模型的构造函数无法接收参数,因此出现此错误。 请参阅CI的模型加载器的源代码,它位于
/YourCIAPP/system/Core/Loader.php
一个名为
Model

在该方法的底部,您可以看到带有此代码的CI负载模型

require_once($mod_path.'models/'.$path.$model.'.php');
$this->_ci_models[] = $name;
$CI->$name = new $model();

请参阅,
CI
仅新建模型对象,模型类的构造函数没有参数。

由于CI模型的构造函数无法接收参数,因此会出现此错误。 请参阅CI的模型加载器的源代码,它位于
/YourCIAPP/system/Core/Loader.php
一个名为
Model

在该方法的底部,您可以看到带有此代码的CI负载模型

require_once($mod_path.'models/'.$path.$model.'.php');
$this->_ci_models[] = $name;
$CI->$name = new $model();


请参阅,
CI
仅新建模型对象,模型类的构造函数中没有参数。

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

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

请将代码发布到创建产品的位置好吗?您可以将var$name改为public$name、public$title和public$price,看看这是否删除了一些警告您正在以正确的方式加载模型,但在构造函数中您需要3个从未发送过的值,或者您退出它,或者像'public function\uu construct'那样初始化它($title1=NULL,$price1=NULL,$name1=NULL)`(这样,您就不能使用变量的一般值)在产品的末尾,我将一个产品定义为:$chair=新家具(“ilove”、“200欧元”、“wood”);print_r($chair->insert_indb($chair));就像我猜的那样,我需要在控制器中定义对象$car=new Furniture。现在有人知道怎么做吗?是的,你在家具中发送构造函数值,但不是在你的产品模型中,你正在扩展。你能在你创建产品的地方发布代码吗?你能把var$name改成pu吗blic$name和public$title和public$price查看这是否删除了一些警告您正在以正确的方式加载模型,但是在您的构造函数中,您需要3个从未发送过的值,或者您退出它或使用类似“public function”的首字母缩写($title1=NULL,$price1=NULL,$name1=NULL)`(这样,您就不能使用变量的一般值)在产品的末尾,我将一个产品定义为:$chair=新家具(“ilove”、“200欧元”、“wood”);print_r($chair->insert_indb($chair));就像我猜的那样,我需要在控制器中定义对象$car=new Furniture。现在有人知道怎么做了吗?是的,你在家具中发送构造函数值,但不是在你的产品模型中,你是extendingok,那么,我是否应该将模型的第一个类设为空构造函数,然后将另一个类产品furnitur设为空e….,我想它会工作,因为我需要加载模型。在控制器中?!@saiedtrifess是的,试试看,我认为它会工作。它没有!有什么想法吗?好吧,那么,我应该让模型的第一个类为空构造函数,然后,让另一个类的产品,家具….,我想它会工作,因为我需要我想加载模型。在控制器中?!@saiedtrifess是的,试试看,我想它会工作的。没有!有什么想法吗?