Я получил эту ошибку на странице products.php
Неустранимая ошибка: Uncaught Error: вызов неопределенного метода stdClass::count() в C:\xampp\htdocs\shopCart\navigation.php:29 Трассировка стека: #0 C:\xampp\htdocs\shopCart\layout_head.php(27 ): include() #1 C:\xampp\htdocs\shopCart\products.php(15): include('C:\xampp\htdocs...') #2 {main} добавлено в C:\xampp\htdocs \shopCart\navigation.php в строке 29
Это часть ошибки страницы navigation.php. Последняя строка 29
// count products in cart
$cart_item = new \stdClass();
$cart_item->user_id=1; // default to user with ID "1" for now
$cart_count=$cart_item->count();
Это функция подсчета в классе cartItem.
class CartItem{
// database connection and table name
private $conn;
private $table_name = "cart_items";
// object properties
public $id;
public $product_id;
public $quantity;
public $user_id;
public $created;
public $modified;
// constructor
public function __construct($db){
$this->conn = $db;
}
// count user's items in the cart
public function count() {
// query to count existing cart item
$query = "SELECT count(*) FROM " . $this->table_name . " WHERE user_id=:user_id";
// prepare query statement
$stmt = $this->conn->prepare( $query );
// sanitize
$this->user_id=htmlspecialchars(strip_tags($this->user_id));
// bind category id variable
$stmt->bindParam(":user_id", $this->user_id);
// execute query
$stmt->execute();
// get row value
$rows = $stmt->fetch(PDO::FETCH_NUM);
// return
return $rows[0];
}
}
как я могу это решить?
$cart_item = new CartItem($db)
. - person Script47   schedule 14.08.2017$cart_item
не является объектом классаCartItem
. ЭтоstdClass
. КлассstdClass
не имеет свойств или методов. - person axiac   schedule 14.08.2017