Beginner error (need help)

Ask about general coding issues or problems here.

Moderators: gesf, Michalio

Post Reply
kekilio10
New php-forum User
New php-forum User
Posts: 1
Joined: Tue Jan 31, 2023 8:08 pm

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)


?>
User avatar
Michalio
Moderator
Moderator
Posts: 361
Joined: Sun Jul 18, 2021 1:33 pm
Location: Poland

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: Select all

$instance = new EnlacesPaginas();
$instance->enlacesPaginasModel();
Free coding lessons: https://php-forum.com/phpforum/viewtopic.php?t=29852
Post Reply