i am stuck in a project when i try to log in my project it shows me
Fatal error: Call to a member function getid() on a non-object in C:\wamp\www\p3\controller\backend.php on line 31
I think its is problem related to my backend.php file+ AdminManager.php file+ Author.php file
this is my backend.php file
enter code here
<?php
// Chargement des classes
require_once('model/PostManager.php');
require_once('model/CommentManager.php');
require_once('model/AdminManager.php');
//use \wwww\p3\model\AdminManager;
function login()
{
require('view/frontend/connectView.php');
}
function connexion($pseudo,$motdepasse)
{
//$postManager = new www\p3\model\PostManager();
// Création d'un objet
$adminManager = new www\p3\model\AdminManager();
//$adminManager = new AdminManager();
$resultat = $adminManager->connected($pseudo,$motdepasse);
if (!$resultat)
{
echo 'Mauvais identifiant ou mot de passe !';
}
else
{
$_SESSION['id'] = $resultat->getId();
$_SESSION['pseudo'] = $resultat->getPseudo();
header('Location: index.php?action=board');
echo 'Vous êtes connecté !';
}
}
function board()
{
$commentManager = new www\p3\model\CommentManager();
$comments = $commentManager->commentaireSignal();
$postManager = new www\p3\model\PostManager();
$posts = $postManager->getPosts();
// calling the view
require('view/backend/addPostView.php');
}
function eraseComment($commentId)
{
$commentManager = new www\p3\model\CommentManager();
$affectedLines = $commentManager->erase($commentId);
if ($affectedLines === false) {
throw new Exception('commentaire déja effacé !');
}
else {
header('Location: index.php');
}
}
function moderateComment($commentId)
{
$commentManager = new www\p3\model\CommentManager();
$affectedLines = $commentManager->moderate($commentId);
if ($affectedLines === false) {
throw new Exception('commentaire déja modéré !');
}
else {
header('Location: index.php');
}
}
function logout() {
// Suppression des variables de session et de la session
//$_SESSION = array();
session_destroy();
// Suppression des cookies de connexion automatique
header('Location: index.php');
}
/**
* method in call from the rounting page under action addPost
* @param $titre
* @param $contenu
*/
function addPost($titre, $contenu)
{
$PostManager = new www\p3\model\PostManager();
$affectedLines = $PostManager->addPost($titre, $contenu);
if ($affectedLines === false) {
throw new Exception('Impossible d\'ajouter le chapitre !');
}
else {
header('Location: index.php?action=post&id=' . $postId);
}
}
function erasePost($postId)
{
$postManager = new www\p3\model\PostManager();
$affectedLines = $postManager->deletePost($postId);
if ($affectedLines === false) {
throw new Exception('article déja effacé !');
}
else {
header('Location: index.php');
}
}
function modifyPost($postId)
{
$postManager = new www\p3\model\PostManager();
$post = $postManager->getPost($postId);
require('view/backend/updatePostView.php');
}
function domodifyPost($id,$titre,$contenu)
{
$PostManager = new www\p3\model\PostManager();
$affectedLines = $PostManager->modifyPost($id,$titre,$contenu);
if ($affectedLines === false) {
throw new Exception('Impossible d\'ajourner le chapitre !');
}
else {
header('Location: index.php?action=board' );
}
}
This is my AdminManager.php file
<?php
namespace www\p3\model;
require_once("model/Manager.php");
require_once("model/Author.php");
class AdminManager extends Manager
{
public function connected ($pseudo,$motdepasse)
{
$db= $this->dbConnect();
$req = $db->prepare('SELECT id,nom,prenom,pseudo,motdepasse FROM auteur
WHERE pseudo=:pseudo AND motdepasse=:motdepasse');
$req->execute(array('pseudo' => $pseudo,'motdepasse' => $motdepasse));
$req->setFetchMode(\PDO::FETCH_CLASS|\PDO::FETCH_PROPS_LATE, "Author");
$resultat = $req->fetch();
return $resultat;
}
}
This is my Author.php file
<?php
namespace www\p3\model;
/**
* Classe which represents an author
* @author David P.
* @version 0.1.0
*/
class Author
{
/**
* @var $id
*/
private $id;
private $firstname;
private $lastname;
private $pseudo;
private $password;
// SETTERS
public function setId($id)
{
$this->id = (int)$id;
}
public function setFirstname($firstname)
{
$this->firstname = $firstname;
}
public function setLastname($lastname)
{
$this->lastname = $lastname;
}
public function setPseudo($pseudo)
{
$this->pseudo = $pseudo;
}
public function setPassword($password)
{
$this->password = $password;
}
//GETTERS
public function getId()
{
return $this->id ;
}
public function getFirstname()
{
return $this->firstname ;
}
public function getLastname()
{
return $this->lastname ;
}
public function getPseudo()
{
return $this->pseudo ;
}
public function getPassword()
{
return $this->password ;
}
}
?>