Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 07/29/2023 in all areas

  1. The radio buttons do not have to be visible, you can hide them and just have a label (which is your image) activate the associated radio. I put together an example. <input type="radio" name="color" value="black" id="black"> <label for="black"> <img src="black.png" alt="black"> </label> You can use CSS to display a border around whichever image is selected, and if you add a class to indication the current one, use a different border to indicate the current item. In my example above, the selected item has a white border, the current has a yellow border.
    1 point
  2. There are no internals of spl_autoload_register with regards to the locating and loading of a class. All the details of how that is done is up to the function you provide. All spl_autoload_register does is add your function to a list of functions that get called when an unknown class is referenced. Your function gets the fully qualified name of the class and has to use that to define that class, typically by converting the name to a file location and including that file. Your example essentially just uses the class name as-is as a file path and attempts to include that file. Since your class is defined as Hello then you get a filename of Hello.class.php with a capital H. Your actual filename however seems to be hello.class.php with a lower-case H. On a case-insensitive filesystem such as windows' ntfs, this would be fine and the file would be loaded. On a case-sensitive filesystem such as linux ext4, this is a problem and the file will fail to load. As mentioned, typically one would just use composer to handle class autoloading rather than defining your own function. Combine it with the PSR-4 standard (and ensure you get your case correct) and you mostly don't have to think about it at all.
    1 point
  3. Some filesystems are case-sensitive, so Hello.class.php and hello.class.php are two completely separate files. You need to either ensure you are using the correct case when creating and referencing your files, or normalize the case in some way (such as making everything lowercase).
    1 point
  4. My suggestion is to use composer https://getcomposer.org/ as it will save you a lot a headaches and you don't have to reinvent the wheel. Then you can just do something like the following -> <?php // Include the configuration file and autoload file from the composer. require_once __DIR__ . '/../config/config.php'; require_once "vendor/autoload.php"; // Import the ErrorHandler and Database classes from the PhotoTech namespace. use brainwave\{ ErrorHandler, Database, Links, ImageContentManager, LoginRepository as Login }; // Instantiate the ErrorHandler class $errorHandler = new ErrorHandler(); // Set the exception handler to use the handleException method from the ErrorHandler instance set_exception_handler([$errorHandler, 'handleException']); // Create a new instance of the Database class $database = new Database(); // Create a PDO instance using the Database class's method $pdo = $database->createPDO(); $login = new Login($pdo); if ($login->check_login_token()) { header('location: dashboard.php'); exit(); } $cms = new ImageContentManager($pdo); a sample class -> <?php // ErrorHandler.php namespace brainwave; use PDOException; use Throwable; use JsonException; class ErrorHandler implements ErrorHandlerInterface { public function handleException(Throwable $e): void { if ($e instanceof PDOException) { error_log('PDO Error: ' . $e->getMessage()); } elseif ($e instanceof JsonException) { error_log('JSON Error: ' . $e->getMessage()); } else { error_log('General Error: ' . $e->getMessage()); } } } I would also check out namespace for PHP classes.
    1 point
This leaderboard is set to New York/GMT-04:00
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.