Installatie Smarty geeft probleem (Opgelost) 		
			
		
		 		
				
		
                        
                 
                 
                 
             
            
            
				
                
                     
                    janssen1   - 06/04/2010 10:01                      
             
             
                        
                Nieuw lid  
                 
                
				
				Hallo, 
 
Ik probeer Smarty te installeren, het lijkt met niet lastig, maar het lukt me toch niet. Er zijn verschillende tutorials die ik heb geprobeerd o.a. http://news.php.net/php.smarty.dev/2703 . Het probleem is dat de pagina die weergegeven wordt leeg is in plaats van dat er een variabele uit de php file weergegeven wordt. 
 
Weet iemand wat er nog fout zou kunnen zijn?				
				 
              
        
		
				
		
            31 antwoorden 
                
                     Gesponsorde links 
                 
                
                    
		
		
	              
		
		
 
                 
            
                    
                         
                         
                         
                     
                    
                    
                        
                             
                            marten   - 06/04/2010 10:07                            
                         
                     
                    
                                                     Beheerder  
                         
                        Wil je eens wat code plaatsen hoe je Smarty gebruikt?  
 
Let wel even op de forum regels (Code langer dan +/- 70 regels plaatsen op www.plaatscode.be en hier de link plaatsen) 
                      
                
                    
                         
                         
                         
                     
                    
                    
                        
                             
                            janssen1   - 06/04/2010 11:23 (laatste wijziging 06/04/2010 11:44)                             
                         
                     
                    
                                                     Nieuw lid  
                         
                        index.php =  
    
    
        
            
                
<?php
// load Smarty library
require('../Smarty/Smarty.class.php');
$smarty = new Smarty;
$smarty->template_dir = '/templates';
$smarty->config_dir = '/config';
$smarty->cache_dir = '/cache';
$smarty->compile_dir = '/templates_c';
$smarty->assign('name','voorbeeldnaam');
$smarty->display('pagina.tpl');
?> 
             
            <?php 
// load Smarty library 
require ( '../Smarty/Smarty.class.php' ) ; 
 
$smarty  =  new  Smarty; 
 
$smarty -> template_dir  =  '/templates' ; 
$smarty -> config_dir  =  '/config' ; 
$smarty -> cache_dir  =  '/cache' ; 
$smarty -> compile_dir  =  '/templates_c' ; 
 
$smarty -> assign ( 'name' , 'voorbeeldnaam' ) ; 
 
$smarty -> display ( 'pagina.tpl' ) ; 
?> 
 
         
         
     
  
 
pagina.tpl = 
    
    
        
            
                
<html>
<body>
Hello, {$name}!
</body>
</html> 
             
            
         
         
     
  
 
Op een webserver staat de map Smarty met daarin de inhoud van lib uit de gedownloade smarty. Ook staat er een map "myFirstSmarty" met daarin 4 mappen "templates", "templates_c", "configs" en "cache". Ook staat de index.php in "myFirstSmarty". Pagina.tpl staat in de map "templates".  
                      
                
                    
                         
                         
                         
                     
                    
                    
                        
                             
                            Ultimatum   - 06/04/2010 12:07                            
                         
                     
                    
                                                     PHP expert  
                         
                        Zet bovenaan je index.php eens error_reporting(E_ALL);. En ik weet niet of het is fout gegaan met kopieren maar je bent ook een > vergeten na ? bij index.php. 
                      
                
                    
                         
                         
                         
                     
                    
                    
                        
                             
                            cloudstrife   - 06/04/2010 12:10                            
                         
                     
                    
                                                     PHP beginner  
                         
                        Ik zou die / voor je directories weghalen.. Verwijst dit immers niet naar de root? 
                      
                
                    
                         
                         
                         
                     
                    
                    
                        
                             
                            janssen1   - 06/04/2010 12:17                            
                         
                     
                    
                                                     Nieuw lid  
                         
                        De > in index.php was inderdaad verkeerd gegaan met kopieren. Het werkt nog niet en ik krijg ook geen errors te zien. De "Hello" van index.tpl wordt ook niet weergegeven. 
 
    
    
        
            
                
<?php
error_reporting(E_ALL);
// load Smarty library
require('../Smarty/Smarty.class.php');
$smarty = new Smarty;
$smarty->template_dir = 'templates';
$smarty->config_dir = 'config';
$smarty->cache_dir = 'cache';
$smarty->compile_dir = 'templates_c';
$smarty->assign('name','voorbeeldnaam');
$smarty->display('pagina.tpl');
?>
 
             
            <?php 
// load Smarty library 
require ( '../Smarty/Smarty.class.php' ) ; 
 
$smarty  =  new  Smarty; 
 
$smarty -> template_dir  =  'templates' ; 
$smarty -> config_dir  =  'config' ; 
$smarty -> cache_dir  =  'cache' ; 
$smarty -> compile_dir  =  'templates_c' ; 
 
$smarty -> assign ( 'name' , 'voorbeeldnaam' ) ; 
 
$smarty -> display ( 'pagina.tpl' ) ; 
?> 
 
         
         
     
  
 
    
    
        
            
                
<html>
<body>
Hello, {$name}!
</body>
</html> 
             
            
         
         
     
  
                      
                
                    
                         
                         
                         
                     
                    
                    
                        
                             
                            ArieMedia   - 06/04/2010 12:18                            
                         
                     
                    
                                                     PHP ver gevorderde  
                         
                        assign moet in een array 
 
    
    
        
            
                require('../Smarty/Smarty.class.php');
$smarty = new Smarty;
$smarty->template_dir = 'templates';
$smarty->config_dir = 'config';
$smarty->cache_dir = 'cache';
$smarty->compile_dir = 'templates_c';
$smarty->assign(array('naam' => 'Voorbeeldnaam'));
$smarty->fetch('pagina.tpl');
?> 
             
            require ( '../Smarty/Smarty.class.php' ) ; 
 
$smarty  =  new  Smarty; 
 
$smarty -> template_dir  =  'templates' ; 
$smarty -> config_dir  =  'config' ; 
$smarty -> cache_dir  =  'cache' ; 
$smarty -> compile_dir  =  'templates_c' ; 
 
$smarty -> assign ( array ( 'naam'  =>  'Voorbeeldnaam' ) ) ;  
$smarty -> fetch ( 'pagina.tpl' ) ; 
?> 
 
         
         
     
  
                      
                
                    
                         
                         
                         
                     
                    
                    
                        
                             
                            janssen1   - 06/04/2010 12:28                            
                         
                     
                    
                                                     Nieuw lid  
                         
                        Dat heb ik aangepast, helaas blijft het probleem. Het lijkt erop dat pagina.tpl er helemaal niet aan te pas komt.  
                      
                
                    
                         
                         
                         
                     
                    
                    
                        
                             
                            marten   - 06/04/2010 13:48                            
                         
                     
                    
                                                     Beheerder  
                         
                        Is het een Windows based webserver of een Linux based webserver? 
                      
                
                    
                         
                         
                         
                     
                    
                    
                        
                             
                            janssen1   - 06/04/2010 14:12                            
                         
                     
                    
                                                     Nieuw lid  
                         
                        Linux based 
                      
                
                    
                         
                         
                         
                     
                    
                    
                        
                             
                            marten   - 06/04/2010 14:19                            
                         
                     
                    
                                                     Beheerder  
                         
                        Dan moet je wel de juiste paden aanhouden: 
 
Windows: 
/website 
 
Linux 
/web/www.domein.nl/templates 
 
etc. 
 
Linux rekent namelijk anders met mappen dan Windows. 
                      
                
                    
                         
                         
                         
                     
                    
                    
                        
                             
                            janssen1   - 06/04/2010 14:34                            
                         
                     
                    
                                                     Nieuw lid  
                         
                        Oke, de server is niet van mezelf, dus ik kan er bij via plesk en ftp. In de tutorial zie ik dat de Smarty map in /usr/local/lib/php/ moet, maar hoe kom ik daarbij? 
                      
                
                    
                         
                         
                         
                     
                    
                    
                        
                             
                            marten   - 06/04/2010 14:41                            
                         
                     
                    
                                                     Beheerder  
                         
                        Het is server afhankelijk. 
 
Het beste kan je het volgende even uitvoeren in je index.php 
 
    
    
        
            
                
print_r($_SERVER['DOCUMENT_ROOT']);
 
             
            print_r ( $_SERVER [ 'DOCUMENT_ROOT' ] ) ;  
         
         
     
  
 
Dan weet je het path. 
                      
                
                    
                         
                         
                         
                     
                    
                    
                        
                             
                            janssen1   - 06/04/2010 14:54                            
                         
                     
                    
                                                     Nieuw lid  
                         
                        /var/www/vhosts/www.domein.nl/httpdocs 
 
In de tutorial staat dat de template files het beste buiten de httpdocs kunnen staan, maar daar heb ik geen rechten, is dat een probleem? 
                      
                
                    
                         
                         
                         
                     
                    
                    
                        
                             
                            marten   - 06/04/2010 14:59                            
                         
                     
                    
                                                     Beheerder  
                         
                        Zet nu eerst eens als test je directory's als volgt: 
 
    
    
        
            
                
$path = '/var/www/vhosts/www.domein.nl/httpdocs/';
// load Smarty library
require($path . 'Smarty/Smarty.class.php');
$smarty = new Smarty;
$smarty->template_dir = $path . 'templates';
$smarty->config_dir = $path . 'config';
$smarty->cache_dir = $path . 'cache';
$smarty->compile_dir = $path . 'templates_c';
$smarty->assign('name','voorbeeldnaam');
$smarty->display('pagina.tpl');
 
             
            $path  =  '/var/www/vhosts/www.domein.nl/httpdocs/' ; 
 
// load Smarty library 
require ( $path  .  'Smarty/Smarty.class.php' ) ; 
 
$smarty  =  new  Smarty; 
 
$smarty -> template_dir  =  $path  .  'templates' ; 
$smarty -> config_dir  =  $path  .  'config' ; 
$smarty -> cache_dir  =  $path  .  'cache' ; 
$smarty -> compile_dir  =  $path  .  'templates_c' ; 
 
$smarty -> assign ( 'name' , 'voorbeeldnaam' ) ; 
 
$smarty -> display ( 'pagina.tpl' ) ; 
 
         
         
     
  
                      
                
                    
                         
                         
                         
                     
                    
                    
                        
                             
                            janssen1   - 06/04/2010 16:12 (laatste wijziging 06/04/2010 16:27)                             
                         
                     
                    
                                                     Nieuw lid  
                         
                        Ik heb nu index.php, templates, templates_c, configs en cache in httpdocs staan en pagina.tpl in templates. 
 
index.php: 
    
    
        
            
                
<?php
$path = '/var/www/vhosts/www.domein.nl/httpdocs';
// put full path to Smarty.class.php
require($path.'Smarty/Smarty.class.php');
$smarty = new Smarty();
$smarty->template_dir = $path.'templates';
$smarty->compile_dir = $path.'templates_c';
$smarty->cache_dir = $path.'cache';
$smarty->config_dir = $path.'configs';
$smarty->assign(array('naam' , 'Voorbeeldnaam'));
$smarty->fetch('pagina.tpl');
?>
 
             
            <?php 
$path  =  '/var/www/vhosts/www.domein.nl/httpdocs' ; 
// put full path to Smarty.class.php 
require ( $path . 'Smarty/Smarty.class.php' ) ; 
$smarty  =  new  Smarty( ) ; 
 
$smarty -> template_dir  =  $path . 'templates' ; 
$smarty -> compile_dir  =  $path . 'templates_c' ; 
$smarty -> cache_dir  =  $path . 'cache' ; 
$smarty -> config_dir  =  $path . 'configs' ; 
 
$smarty -> assign ( array ( 'naam'  ,  'Voorbeeldnaam' ) ) ;  
$smarty -> fetch ( 'pagina.tpl' ) ; 
?> 
 
         
         
     
  
 
pagina.tpl: 
    
    
        
            
                
<html>
<body>
Hello, {$name}!
</body>
</html>
 
             
            
         
         
     
  
 
maar als ik naar index.php ga wordt er niets weergegeven. 
 
EDIT: In de httpdocs staat ook een map Smary met de inhoud van lib 
                      
                
                    
                         
                         
                         
                     
                    
                    
                        
                             
                            janssen1   - 07/04/2010 08:51 (laatste wijziging 07/04/2010 10:23)                             
                         
                     
                    
                                                     Nieuw lid  
                         
                        Oke, dat staat nu goed: 
 
    
    
        
            
                
<?php
$path = '/var/www/vhosts/www.domein.nl/httpdocs/';
// put full path to Smarty.class.php
require($path.'Smarty/Smarty.class.php');
$smarty = new Smarty();
$smarty->template_dir = $path.'templates';
$smarty->compile_dir = $path.'templates_c';
$smarty->cache_dir = $path.'cache';
$smarty->config_dir = $path.'configs';
$smarty->assign(array('name' => 'Voorbeeldnaam'));
$smarty->fetch('pagina.tpl');
?>
 
             
            <?php 
$path  =  '/var/www/vhosts/www.domein.nl/httpdocs/' ; 
// put full path to Smarty.class.php 
require ( $path . 'Smarty/Smarty.class.php' ) ; 
$smarty  =  new  Smarty( ) ; 
 
$smarty -> template_dir  =  $path . 'templates' ; 
$smarty -> compile_dir  =  $path . 'templates_c' ; 
$smarty -> cache_dir  =  $path . 'cache' ; 
$smarty -> config_dir  =  $path . 'configs' ; 
 
$smarty -> assign ( array ( 'name'  =>  'Voorbeeldnaam' ) ) ;  
$smarty -> fetch ( 'pagina.tpl' ) ; 
?> 
 
         
         
     
  
 
    
    
        
            
                
<html>
<body>
Hello, {$name}!
</body>
</html>
 
             
            
         
         
     
  
 
Hij geeft nog niets weer in de browser, het lijkt te gaan om de regel: 
require($path.'Smarty/Smarty.class.php'); 
 
want als ik daarvoor een echo zet wordt die weergegeven, maar daarna een echo laat niets zien. 
 
EDIT: Dit kwam door de verkeerde url in $path. Nu werken de echos op elke plek ni de PHP, maar wordt wel een lege pagina weergegeven. 
                      
                
                    
                         
                         
                         
                     
                    
                    
                        
                             
                            janssen1   - 07/04/2010 10:33                            
                         
                     
                    
                                                     Nieuw lid  
                         
                        Dat laat niets zien...elke keer een lege pagina met 
    
    
        
            
                
<html>
 <head></head>
 <body></body>
</html>
 
             
            
         
         
     
  
 
Alsof die pagina.tpl niet kan vinden, die staat in de map /var/www/vhosts/www.domein.nl/httpdocs/templates, zoals het volgens mij hoort. 
                      
                
                    
                         
                         
                         
                     
                    
                    
                        
                             
                            janssen1   - 07/04/2010 10:43                            
                         
                     
                    
                                                     Nieuw lid  
                         
                        Er is geen tekst te zien en er staat al "Hello," in de tpl, maar dat wordt niet weergegeven. 
Het probleem ligt dus bij de PHP...maar wat precies, het lijkt alsof hij heel smarty niet kent, maar smarty staat er wel. 
 
templates_c en cache zijn schrijfbaar voor PHP. 
                      
                
                    
                         
                         
                         
                     
                    
                    
                        
                             
                            Jurgo   - 07/04/2010 10:51                            
                         
                     
                    
                                                     PHP interesse  
                         
                        include je wel de smarty class bestanden 
Misschien gaat het wel fout bij het assignen van het php bestand aan het tpl bestand. Kun je laten zien hoe je dit doet? 
                      
                
                    
                         
                         
                         
                     
                    
                    
                        
                             
                            ArieMedia   - 07/04/2010 10:52                            
                         
                     
                    
                                                     PHP ver gevorderde  
                         
                        Jurgo  schreef:
include je wel de smarty class bestanden 
Misschien gaat het wel fout bij het assignen van het php bestand aan het tpl bestand. Kun je laten zien hoe je dit doet?
 Als je de vorige pagina's bekijkt staat er hoe hij dat doet. 
                      
                
                    
                         
                         
                         
                     
                    
                    
                        
                             
                            genkstar   - 07/04/2010 12:01                            
                         
                     
                    
                                                     Nieuw lid  
                         
                        Heb je wel lees-rechten op die template files? 
En Als dat toch niet lukt, zou ik opnieuw de Smarty library downloaden en vervangen met de oude, heb ik ook al eens meegemaakt. 
 
$smarty->assign('name', 'value'); 
 
En zo ken je waardes toe aan smarty-variabelen.. 
                      
                
                    
                         
                         
                         
                     
                    
                    
                        
                             
                            janssen1   - 07/04/2010 12:05 (laatste wijziging 07/04/2010 12:10)                             
                         
                     
                    
                                                     Nieuw lid  
                         
                        Ik heb leesrechten op de template files. En dat opnieuw installeren/vervangen van de Smarty files heb ik ook al vaak gedaan. 
 
Irritant probleem, omdat het zo makkelijk lijkt en het toch niet lukt. 
 
EDIT: de smarty files toch nog een keer vervangen, maar dat maakt geen verschil. 
                      
                
                    
                         
                         
                         
                     
                    
                    
                        
                             
                            ArieMedia   - 07/04/2010 12:29                            
                         
                     
                    
                                                     PHP ver gevorderde  
                         
                        genkstar  schreef:
Heb je wel lees-rechten op die template files? 
En Als dat toch niet lukt, zou ik opnieuw de Smarty library downloaden en vervangen met de oude, heb ik ook al eens meegemaakt. 
 
$smarty->assign('name', 'value'); 
 
En zo ken je waardes toe aan smarty-variabelen..
 Jij gaat recht in tegen wat ik zeg. De waardes die je in smarty assigned moeten een array zijn, anders doet hij het niet.  
                      
                
                    
                         
                         
                         
                     
                    
                    
                        
                             
                            janssen1   - 08/04/2010 08:53                            
                         
                     
                    
                                                     Nieuw lid  
                         
                        Zou iemand er meer mee kunnen als ik de link naar de pagina geef? 
                      
                
                    
                         
                         
                         
                     
                    
                    
                        
                             
                            janssen1   - 08/04/2010 16:13 (laatste wijziging 08/04/2010 16:24)                             
                         
                     
                    
                                                     Nieuw lid  
                         
                        http://hoogvliet.gkv.nl/test / 
 
Daar staat het nu, probeer nu te debuggen, maar dat lijkt ook niet te werken. Nu wel display ipv fetch gebruikt, volgens de documentatie mag: echo fetch() of display()  
 
    
    
        
            
                
<?php
error_reporting(E_ALL);
$path = '/var/www/vhosts/hoogvliet.gkv.nl/httpdocs/test/';
// put full path to Smarty.class.php
require_once($path.'Smarty/Smarty.class.php');
$smarty = new Smarty();
$smarty->compile_check = true;
$smarty->debugging = true;
$smarty->template_dir = $path.'templates';
$smarty->compile_dir = $path.'templates_c';
$smarty->cache_dir = $path.'cache';
$smarty->config_dir = $path.'configs';
$smarty->assign(array('name' => 'Voorbeeldnaam'));
$smarty->display('pagina.tpl');
?>
 
             
            <?php 
$path  =  '/var/www/vhosts/hoogvliet.gkv.nl/httpdocs/test/' ; 
// put full path to Smarty.class.php 
require_once ( $path . 'Smarty/Smarty.class.php' ) ; 
$smarty  =  new  Smarty( ) ; 
$smarty -> compile_check  =  true ; 
$smarty -> debugging  =  true ; 
 
$smarty -> template_dir  =  $path . 'templates' ; 
$smarty -> compile_dir  =  $path . 'templates_c' ; 
$smarty -> cache_dir  =  $path . 'cache' ; 
$smarty -> config_dir  =  $path . 'configs' ; 
 
$smarty -> assign ( array ( 'name'  =>  'Voorbeeldnaam' ) ) ;  
$smarty -> display ( 'pagina.tpl' ) ; 
?> 
 
         
         
     
  
 
    
    
        
            
                
<html>
<body>
{debug}
Hello, {$name}!
</body>
</html>
 
             
            
         
         
     
  
                      
                
                    
                         
                         
                         
                     
                    
                    
                        
                             
                            genkstar   - 08/04/2010 20:33                            
                         
                     
                    
                                                     Nieuw lid  
                         
                        Zet eens onder error_reporting(E_ALL); 
ini_set('display_errors', 1); en bekijk je pagina nog eens.. 
                      
                
                    
                         Gesponsorde links 
                     
                    
                        
		
		
	              
		
		
 
                     
                
Dit onderwerp is gesloten .