Why do not you show me the content of my website 000webhost?

0

I have already finished a mini project, it works perfect on my PC "Localhost" but when I want to upload it to 000webhost it goes up all right, but when I want to see a view it does not show it, but no error appears. I think it's the .htaccess or the index.php Help !!.

The model that follows my page is MVC.

.htaccess

<IfModule mod_rewrite.c>
#Activar rewrite
RewriteEngine on
ErrorDocument 404 https://stevencoailazaa.000webhostapp.com/error

RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f

RewriteRule ^(.*)/(.*) index.php?controller=$1&action=$2
</Ifmodule>

Index.php

<?php


session_start();
require_once 'autoload.php';
require_once 'config/db.php';
require_once 'config/parameters.php';
require_once 'helpers/utils.php';

require_once 'views/layout/header.php';


function show_error() {
    $error = new errorController();
    $error->index();
}

if (isset($_GET['controller'])) {
    $nombre_controlador = $_GET['controller'] . 'Controller';
} elseif (!isset($_GET['controller']) && !isset($_GET['action'])) {
    $nombre_controlador = controller_default;
} else {
    show_error();
    exit();
}

if (class_exists($nombre_controlador)) {
    $controlador = new $nombre_controlador();

    if (isset($_GET['action']) && method_exists($controlador, $_GET['action'])) {
        $action = $_GET['action'];
        $controlador->$action();
    } elseif (!isset($_GET['controller']) && !isset($_GET['action'])) {
        $action_default = action_default;
        $controlador->$action_default();
    } else {
        show_error();
    }
} else {
    show_error();
}

require_once 'views/layout/footer.php';

?>

Project image

ProductController.php

<?php

require_once 'models/producto.php';

class productoController {

    public function index() {
        $producto = new Producto();
        $productos = $producto->getRandom(6);

        require_once 'views/producto/destacados.php';
    }

    public function ver() {
        if (isset($_GET['id'])) {
            $id = $_GET['id'];

            $producto = new Producto();
            $producto->setId($id);

            $pro = $producto->getOne();   
        } 
        require_once 'views/producto/ver.php';
    }

    public function gestion() {
        Utils::isAdmin();

        $producto = new Producto();
        $productos = $producto->getAll();
        require_once 'views/producto/gestion.php';
    }

    public function save() {
        Utils::isAdmin();

        if (isset($_POST)) {
            $nombre = isset($_POST['nombre']) ? $_POST['nombre'] : false;
            $descripcion = isset($_POST['descripcion']) ? $_POST['descripcion'] : false;
            $precio = isset($_POST['precio']) ? $_POST['precio'] : false;
            $stock = isset($_POST['stock']) ? $_POST['stock'] : false;
            $categoria = isset($_POST['categoria']) ? $_POST['categoria'] : false;
            //$imagen = isset($_POST['imagen']) ? $_POST['imagen'] : false;

            if ($nombre && $descripcion && $precio && $stock && $categoria) {
                $producto = new Producto();
                $producto->setNombre($nombre);
                $producto->setDescripcion($descripcion);
                $producto->setPrecio($precio);
                $producto->setStock($stock);
                $producto->setCategoria_id($categoria);

                //GUARDAR LA IMAGEN
                if (isset($_FILES['imagen'])) {
                    $file = $_FILES['imagen'];
                    $filename = $file['name'];
                    $mimetype = $file['type'];


                    if ($mimetype == "image/jpg" || $mimetype == "image/jpeg" || $mimetype == "image/png" || $mimetype == "image/git") {
                        if (!is_dir('uploads/images')) {
                            mkdir('uploads/images', 0777, TRUE);
                        }

                        move_uploaded_file($file['tmp_name'], 'uploads/images/' . $filename);
                        $producto->setImagen($filename);
                    }
                }


                if (isset($_GET['id'])) {
                    $id = $_GET['id'];
                    $producto->setId($id);

                    $save = $producto->edit();
                } else {
                    $save = $producto->save();
                }


                if ($save) {
                    $_SESSION['producto'] = 'complete';
                } else {
                    $_SESSION['producto'] = 'failed';
                }
            } else {
                $_SESSION['producto'] = 'failed';
            }
        } else {
            $_SESSION['producto'] = 'failed';
        }
        header("Location:" . base_url . 'producto/gestion');
    }

    public function editar() {
        Utils::isAdmin();

        if (isset($_GET['id'])) {
            $id = $_GET['id'];
            $edit = true;

            $producto = new Producto();
            $producto->setId($id);

            $pro = $producto->getOne();

            require_once 'views/producto/editar.php';
        } else {
            header("Location:" . base_url . 'producto/gestion');
        }
    }

    public function eliminar() {
        Utils::isAdmin();

        if (isset($_GET['id'])) {
            $id = $_GET['id'];

            $producto = new Producto();
            $producto->setId($id);
            $delete = $producto->delete();

            if ($delete) {
                $_SESSION['delete'] = 'complete';
            } else {
                $_SESSION['delete'] = 'failed';
            }
        } else {
            $_SESSION['delete'] = 'failed';
        }
        header("Location:" . base_url . 'producto/gestion');
    }

}

autoload.php

<?php

function controllers_autoload($classname) {
    require_once 'controllers/' . $classname . '.php';
}

spl_autoload_register('controllers_autoload');
    
asked by Steven Angel Coaila Zaa 14.12.2018 в 23:38
source

1 answer

0

To solve this problem you just have to change the name of the files in the controllers folder. Its start is Shift, just change it to a lower case: UserController to userController

And last and most important in the autoload.php change the include_once () by require_once ()

INCORRECT FORM

function controllers_autoload($classname) {
    include_once 'controllers/' . $classname . '.php';
}

spl_autoload_register('controllers_autoload');

CORRECT FORM

function controllers_autoload($classname) {
        require_once 'controllers/' . $classname . '.php';
    }

    spl_autoload_register('controllers_autoload');
    
answered by 15.12.2018 в 06:15