Jump to content

[PHP] include() Filename cannot be empty


HerrPNut

Recommended Posts

I have a weird problem.

I declare

$this->file = 'controller.php';

then

include($this->file); 

and nothing happens. When I surround the include with an if-statement:

if(include($this->file))
{
    echo "OK";
}
else
{
   echo "NOT OK";
}

I get this error:

 

*Warning: include() [function.include]: Filename cannot be empty in C:\wamp\www\...\ on line 70

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/192497-php-include-filename-cannot-be-empty/
Share on other sites

now it shows me "it works"

So the problem has to be in the controller class?

this is the controller class code:

class controller extends ControllerBase {
    function index() {
        include_once('../model/gebruiker.php');
        $gebruiker = new GebruikerModel();

        if (isset ($_GET['id'])) {
            if(is_numeric($_GET['id'])) {
                /**
                 * Haal de waardes uit de database. Het model zet deze in de klasse variabelen
                 * dus kunnen we ze aanroepen met $object_naam->klassevariabelenaam;
                 */

                $id = $_GET['id'];
                $getGebruiker = $gebruiker->getGebruiker($id);
                $gebruikernaam = $gebruiker->get_naam();
                $gebruikervoornaam = $gebruiker->get_voornaam();
                /**
                 * Zet de verschillende waardes in het register zodat we deze in de view kunnen gebruiken
                 */

                $this->registry['template']->set('naam',$gebruikernaam);
                $this->registry['template']->set('voornaam',$gebruikervoornaam);

                /**
                 * Verwijzing naar de view.
                 * Dit laat de view met de naam wat tussen de haken van show staat.
                 * Hier is het dus de view media. Deze staat in de map templates en
                 * heeft de naam <viewnaam>.php
                 */

                $this->registry['template']->show('gebruiker');

            }
        }else {
            /**
             * Er is geen media id meegegeven in de url dus toon gewoon de view.
             * Hier kan je natuurlijk ook een model functie aanroepen die alle categorien
             * laat zien zoals we dat in het voorbeeld gaan doen.
             */
            $this->registry['template']->show('gebruiker');
        }
    }
}

 

 

edit: if i remove the "extends controllerBase" everything works...

this is the code from controllerbase:

<?php
abstract class ControllerBase {
    protected $registry;
    
    function __construct($registry) {
        $this->registry = $registry;
    }
    
    abstract function index();
}
?>

 

but Controller HAS to inherit ControllerBase

[ot]

include does not return any value so there is no point in checking if it returns true / false.

It does return values. Behaviour is FALSE on error (and a warning is issued), 1 for a 'normal' include or whatever if the included file uses return "whatever";[/ot]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.