Beginner error (need help)

kekilio10

New member
Hi. I'm learning PHP from a tutorial in youtube (https://www.youtube.com/watch?v=vgsLhG3VDCA&t=4s). Everything was going good until I tried to run the code and I get this error that I don't understand at minute 34:37. I did the tutorial all over again and still getting the same error. Help please.

Fatal error: Uncaught Error: Non-static method EnlacesPaginas::enlacesPaginasModel() cannot be called statically in D:\XAMPP\htdocs\cursoPHP\03.MVC\controllers\controller.php:22 Stack trace: #0 D:\XAMPP\htdocs\cursoPHP\03.MVC\views\template.php(59): MvcController->enlacesPaginasController() #1 D:\XAMPP\htdocs\cursoPHP\03.MVC\controllers\controller.php(10): include('D:\\XAMPP\\htdocs...') #2 D:\XAMPP\htdocs\cursoPHP\03.MVC\index.php(10): MvcController->plantilla() #3 {main} thrown in D:\XAMPP\htdocs\cursoPHP\03.MVC\controllers\controller.php on line 22

This are the codes from the different files:
D:\XAMPP\htdocs\cursoPHP\03.MVC\controllers\controller.php:22

<?php

class MvcController{

#LLAMADA A LA PLANTILLA
#------------------------------------

public function plantilla(){

include "views/template.php"; #This is (10)

}

#INTERACCION DEL USUARIO
#------------------------------------
public function enlacesPaginasController(){

$enlacesController = $_GET["action"];



$respuestas = EnlacesPaginas::enlacesPaginasModel($enlacesController); #This is (22)

include $respuesta;

}
}

?>

D:\XAMPP\htdocs\cursoPHP\03.MVC\views\template.php(59)

Before the next code there is a html template
<?php
include "modules/navegacion.php";

?>

<section>

<?php
$mvc = new MvcController();
$mvc -> enlacesPaginasController(); #This is (59)
?>

</section>

D:\XAMPP\htdocs\cursoPHP\03.MVC\index.php(10)

<?php

#EL INDEX> En el mostrarermos la salida de las vistas al usuario y tambien a traves de el enviaremos las distintas acciones que el usuario envie al controlador
#requiered() estable que el codigo del archivo invocado es requerido, es decir, obligatorio para el funcionamiento del programa. Por ello, si el archivo especificado en la funcion require() no se encuentra saltara un error "PHP fatal error" y el programa PHP se detendra.

require_once "controllers/controller.php";
require_once "models/model.php";

$mvc = new MvcController();
$mvc -> plantilla(); #This is (10)


?>
 
the class EnlacesPaginas have method named enlacesPaginasModel tha is not static, so to use this method you need to create an instance of the class EnlacesPaginas and then you need to call the method from the class instance like this:
Code:
$instance = new EnlacesPaginas();
$instance->enlacesPaginasModel();
 
Back
Top