I'm beginning to learn the object-oriented programming in order to make a project : while I have some files that have been given to help me by my internship tutor, I can't manage to work with it. So I struggle to make a basic insertion for registration.
Here is the model class Player :
<?php
declare(strict_types=1);
namespace RpgForum;
require_once(__DIR__ . '/../utils.php');
use \Ank\Config;
use \Ank\Repository;
use \Ank\Entity;
use \Ank\Db;
class Player extends Entity{
protected function setPlayer(string $username, string $mail, string $password){
$db = getInstance();
var_dump($db);
$sql = $db->prepare('INSERT INTO player SET username = :username, mail = :mail, password = :password');
$sql->bindValue(':username', $username);
$sql->bindValue(':mail', $mail);
$sql->bindValue(':password', crypt($password, gen_salt("md5")));
$res = $sql->execute();
}
}
And so here is the error :
Fatal error: Uncaught Error: Call to undefined function RpgForum\getInstance() in /app/src/RpgForum/Player.php:68 Stack trace: #0 /app/src/controller/connectionController.php(18): RpgForum\Player->setPlayer() #1 /app/src/controller/connectionController.php(25): RpgForum\Register->register() #2 {main} thrown in /app/src/RpgForum/Player.php on line 68
Here is the thing : I have a class Player that uses a class Db and extends a class called Entity. getInstance()
function is a public static function that I found in the Db
class.
And so, I have an error telling that some of my attributes or methods are not defined, as if the link between classes could not be done...
So I tried to change what should be used or extended in term of classes. I tried to understand what my tutor gave me but it only disrupted some of my neurons. I took some online free courses to upgrade my knowledge and so I gave it a try with my new skills as I declared classes, new objects, some parameters and tried make a link with the database and view via the controller. But in the end I can't see in the database the new player, showing me that something failed (see the error thrown).