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
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

Link to comment
Share on other sites

[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]

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.