Неустранимая ошибка: неперехваченная ошибка: класс 'App \ DB \ QueryBuilder' - PullRequest
0 голосов
/ 17 июня 2020

У меня проблема с пространством имен. И я не могу понять, где я сделал ошибку.

Это полная ошибка:

Неустранимая ошибка: Неперехваченная ошибка: Класс 'App \ DB \ QueryBuilder' не найден в D: \ OSPanel \ domains \ mar \ app \ controllers \ HomeController. php: 21 Трассировка стека: # 0 D: \ OSPanel \ domains \ mar \ public \ index. php (53): App \ controllers \ HomeController -> index (Array) # 1 {main} добавлен в D: \ OSPanel \ domains \ mar \ app \ controllers \ HomeController. php в строке 21

<?php

    namespace App\controllers;

    use App\DB\QueryBuilder;
    use League\Plates\Engine;

    class HomeController
    {
        private $templates;
            public function __construct()
            {

                $this->templates = new Engine('../app/views');
            }

        public function index($vars){

             $db = new QueryBuilder();
                $posts = $db->getAll('new_db');
                echo $this->templates->render('index.view', ['posts' => $posts]);

        }
    }

Это код в QueryBuilder

<?php

namespace App\DB;

use Aura\SqlQuery\QueryFactory;
use PDO;


class QueryBuilder
{
    private $pdo;
    private $queryFactory;

    public function __construct()
    {
        $this->pdo = new PDO("mysql:host=localhost; dbname=marlin",'root');
        $this->queryFactory = new QueryFactory('mysql');

    }

    public function getAll($table){
        $select = $this->queryFactory->newSelect('mysql');

        $select->cols(['*'])
                ->from($table);

        $sth = $this->pdo->prepare($select->getStatement());

        $sth->execute($select->getBindValues());

        return $sth->fetchall(PDO::FETCH_ASSOC);
    }


    public function getOne($id, $table)
    {
        $select = $this->queryFactory->newSelect();
        $select->cols([':id'])
                ->from($table)
        ->bindValues([
            ':id'=> $id
        ]);

        $sth = $this->pdo->prepare($select->getStatement());

        $sth->execute($select->getBindValues());

        return $sth->fetch(PDO::FETCH_ASSOC);
    }

    public function create($table, $value){
        $insert = $this->queryFactory->newInsert();

        $insert->into($table)
        ->cols([
            'title' => $value
        ]);

        $sth = $this->pdo->prepare($insert->getStatement());

        $sth->execute($insert->getBindValues());
    }

    public function update($table, $id, $value){
        $update = $this->queryFactory->newUpdate();

        $update
            ->table($table)                  // update this table
            ->cols($value)
            ->where('id = :id')           // AND WHERE these conditions
            ->bindValues([                  // bind these values to the query
                ':id'   => $id
            ]);

            $sth = $this->pdo->prepare($update->getStatement());

            $sth->execute($update->getBindValues());
    }

    public function delete($table, $id){
        $delete = $this->queryFactory->newDelete();

        $delete
            ->from($table)                   // FROM this table
            ->where('id = :id')           // AND WHERE these conditions
            ->bindValues([                  // bind these values to the query
                ':id' => $id,
            ]);



            $sth = $this->pdo->prepare($delete->getStatement());

            $sth->execute($delete->getBindValues());

    }

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