thecodeholic / php-mvc-framework

PHP MVC Framework
https://www.youtube.com/playlist?list=PLLQuc_7jk__Uk_QnJMPndbdKECcTEwTA1
478 stars 180 forks source link

Issues with creating the instance for the migration class. #25

Closed ghost closed 2 years ago

ghost commented 2 years ago
function applyMigrations() {
    $this->createMigrationsTable();
    $appliedMigrations = $this->getAppliedMigrations();

    $newMigrations = [];
    $files = scandir(Application::$ROOT_DIR . '/migrations');
    $toApplyMigrations = array_diff($files, $appliedMigrations);

    foreach ($toApplyMigrations as $migration) {
      if ($migration === '.' || $migration === '..') {
        continue;
      }

      require_once Application::$ROOT_DIR .'./migrations/'.$migration;
      $className = pathinfo($migration, PATHINFO_FILENAME);

      echo "<pre>";
      var_dump($className);
      echo "</pre>";
      exit;

      $instance = new $className();      //ISSUE CREATING THIS INSTANCE!!
      $this->log("Applying migration $migration");
      $instance->up();
      $this->log("Applied migration $migration");
      $newMigrations[] = $migration;
      echo "<pre>";
      var_dump($instance);
      echo "</pre>";
      exit;
    }
  }

Hi thecodeholic, i am having this error creating the instance for the migration class:

Fatal error: Uncaught Error: Class "m0001_initial" not found in C:\xampp\htdocs\simpleMVC\core\Database.php

would really appreciate if you could help me.

I really do appreciate your PHP tutorials, it makes me really enjoy coding PHP!