Неустранимая ошибка: класс 'Db_object' не найден в C: \ xampp \ htdocs \ cms_pro \ admin \ includes \ photos. php в строке 4 - PullRequest
0 голосов
/ 22 апреля 2020

Вставка данных невозможна, так как не получается родительский класс. Я получаю следующую ошибку:

Неустранимая ошибка: класс 'Db_object' не найден в C: \ xampp \ htdocs \ cms_pro \ admin \ includes \ photos. php в строке 4 родительский класс не найден в дочернем классе

init. php

<?php
defined('DS') ? null : define('DS', DIRECTORY_SEPARATOR);
define('SITE_ROOT', 'C:' . DS . 'xampp'.DS.'htdocs'.DS.'oop_aryan'.DS.'cms_pro');
defined('INCLUDES_PATH') ? null : define('INCLUDES_PATH', SITE_ROOT.DS.'admin'.DS.'includes');
include "new_config.php";
include"session.php";
include "database.php";
require_once("new_config.php");
require_once("db_object.php");
require_once("photos.php");
include "user.php";
include"functions.php";



?> 

db_object. php

<?php 


class Db_object
{

protected static $db_table="users";
public static  function find_all(){
    global $database;
return static::find_by_query("SELECT * FROM ".static::$db_table." ");
}

public static  function find_by_id($id){
    global $database;
 $raise=static::find_by_query("SELECT * FROM  ".static::$db_table." WHERE id= $id LIMIT 1");
 return !empty($raise) ? array_shift($raise): false;


}



public static  function find_by_query($sql){
    global $database;
$raise=$database->query($sql);
$object_array=array();
while ($row=mysqli_fetch_array($raise)) {
    $object_array[]=static::instantation($row);

}
 return $object_array;
}




public static  function instantation($don){

$calling_class=get_called_class();

  $the_object= new $calling_class;

foreach ($don as $the_attribute => $value) {
  if ($the_object->has_the_attribute($the_attribute)){

    $the_object->$the_attribute=$value;
   }
  }
return $the_object; 
}


private  function has_the_attribute($the_attribute){

    $the_objectpro=get_object_vars($this);

    return array_key_exists($the_attribute, $the_objectpro); 
}   


protected function properties(){

   // return get_object_vars($this);
        $properties=array();
foreach (static::$db_table_fileds as $db_filed) {
  if(property_exists($this,$db_filed)){

    $properties[$db_filed]=$this->$db_filed;
  }
}
return $properties;
}


protected function clean_properties(){
global $database;
$clean_properties=array();
foreach ($this->properties() as $key => $value) {
  $clean_properties[$key]=$database->escape_string($value);
}
return $clean_properties;

}




public function save(){

  return isset($this->id) ? $this->update() : $this->create();
}



public function create(){

global $database;
$properties=$this->clean_properties();

$sql= "INSERT INTO ". static::$db_table."(".implode(",",array_keys($properties)).")";
$sql .= " VALUES('".implode("','",array_values($properties))."')";


//
if($database->query($sql)){
  $this->id=$database->insert_id();
  return true;
}else{
  return false;
}



}

public function update(){
global $database;
$properties=$this->clean_properties();
$properties_pairs=array();
foreach ($properties as $key => $value) {
  $properties_pairs[]="{$key}='{$value}'";

}

  $sql= "UPDATE ". static::$db_table." SET ";
$sql .=implode(",", $properties_pairs);
$sql .= "WHERE id=".$database->escape_string($this->id);


$database->query($sql);

return(mysqli_affected_rows($database->connection) == 1) ? true : false;


}

 public function delete(){
 global $database;
   $sql=" DELETE FROM ". static::$db_table." WHERE id= ".$database->escape_string($this->id)." LIMIT 1 ";
   $database->query($sql);
 return(mysqli_affected_rows($database->connection) == 1) ? true : false;
 }





}







 ?> 

фото. php

class Photo extends Db_object
{

protected static $db_table="photos";
protected static $db_table_fileds=array('id','title','caption','description','filename','alternate_text','type','size');
public $id;
public $title;
public $caption;
public $description;
public $filename;
public $alternate_text;
public $type;
public $size;

public $tmp_path;
public $upload_directory="images";
public $errors=array();
public $upload_errors_array= array(
UPLOAD_ERR_OK => "There is no error, the file uploaded with success.",
UPLOAD_ERR_INI_SIZE => "The uploaded file exceeds the upload_max_filesize directive in php.ini ",
UPLOAD_ERR_PARTIAL  => "The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.",
UPLOAD_ERR_NO_FILE => " No file was uploaded.",
UPLOAD_ERR_NO_TMP_DIR => " Missing a temporary folder.",
UPLOAD_ERR_CANT_WRITE =>"Failed to write file to disk.",
UPLOAD_ERR_EXTENSION =>"A PHP extension stopped the file upload. ");


public function set_file($file){
if (empty($file)|| !$file || !is_array($file)) {

    $this->errors[]="there is no file uploaded here";
    return false;
}elseif($file['error'] !=0){
    $this->errors[]=$this->upload_errors_array[$file['error']];
    return false;
}
else{

$this->filename=basename($file['name']);

$this->tmp_path=$file['tmp_name'];

$this->type=$file['type'];

$this->size=$file['size'];


}

}


public function picture_img_path(){

return $this->upload_directory .DS. $this->filename;
}




///file set

public function save(){

if($this->id){
    $this->update();

}else{

     if(!empty($this->errors))
      {
        return false;
        }
       if(empty($this->filename) || empty($this->tmp_path))
        {
         $this->errors[]="This file was not available";
         return false;
        }

$target_path=SITE_ROOT.DS. 'admin' .DS. $this->upload_directory .DS. $this->filename; 

    if(file_exists($target_path)){

    $this->errors[]="The file {$this->filename} already exists";
    return false;
    }


    if(move_uploaded_file($this->tmp_path,$target_path)){

        if($this->create()){
         unset($this->tmp_path);  
           return true;
         }
      }
    else{

    $this->errors[]="This file directory probably does not have permission";
    return false;
     }

}


}



public function delete_photo(){

if($this->delete()){

$target_path=SITE_ROOT.DS. 'admin' .DS. $this->picture_img_path();
return unlink($target_path) ? true : false;

}
else{
return false;
}



}



} 
//class end



 ?>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...