HerrPNut Posted February 18, 2010 Share Posted February 18, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/192497-php-include-filename-cannot-be-empty/ Share on other sites More sharing options...
trq Posted February 18, 2010 Share Posted February 18, 2010 include does not return any value so there is no point in checking if it returns true / false. What does.... echo $this->file; produce? Quote Link to comment https://forums.phpfreaks.com/topic/192497-php-include-filename-cannot-be-empty/#findComment-1014240 Share on other sites More sharing options...
HerrPNut Posted February 18, 2010 Author Share Posted February 18, 2010 it shows controller.php if i check if the file exisits: if (file_exists($this->file)){ echo 'EXISTS<br />'; }else{ echo 'EXISTS NOT<br />'; } it shows EXISTS Quote Link to comment https://forums.phpfreaks.com/topic/192497-php-include-filename-cannot-be-empty/#findComment-1014243 Share on other sites More sharing options...
LeadingWebDev Posted February 18, 2010 Share Posted February 18, 2010 try include controller.php and type inside controller echo "it works!"; its seems to be work. Quote Link to comment https://forums.phpfreaks.com/topic/192497-php-include-filename-cannot-be-empty/#findComment-1014244 Share on other sites More sharing options...
HerrPNut Posted February 18, 2010 Author Share Posted February 18, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/192497-php-include-filename-cannot-be-empty/#findComment-1014245 Share on other sites More sharing options...
trq Posted February 18, 2010 Share Posted February 18, 2010 So the problem has to be in the controller class? What problem? Quote Link to comment https://forums.phpfreaks.com/topic/192497-php-include-filename-cannot-be-empty/#findComment-1014262 Share on other sites More sharing options...
salathe Posted February 18, 2010 Share Posted February 18, 2010 [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] Quote Link to comment https://forums.phpfreaks.com/topic/192497-php-include-filename-cannot-be-empty/#findComment-1014283 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.