• 18-11-2010, 11:30:37
    #1
    Smarty ile WHİLE döngüsünü tam kullanamıyorum index.php de
     $sor=mysql_query("SELECT * FROM forum");
    while($liste=mysql_fetch_array($sor)): 
    $forum[] = $liste;
    endwhile;
    $smarty->assign("$forum",forum);
    templates/index.html de ise şöyle yapıyorum
     {foreach from=$forum item=sira} 
    < a href="?forum_id={$sira.id}">{$sira.isim} 
    {/foreach}
    Bi türlü veritabanındaki verileri listeliyemedim gitti. acemiyim smartyde
  • 18-11-2010, 17:53:44
    #2
    Yardım Edebilecek Arkadaş varmı ?? çok sıkıldım verileri çekemedim bi türlü veri tabanından. Herkese Şimdiden teşekkür ederim.
  • 18-11-2010, 18:26:04
    #3
    Üyeliği durduruldu
    Example 7.30. A simple {foreach} loop

    <?php
    $arr = array('red', 'green', 'blue');
    $smarty->assign('myColors', $arr);
    ?>
    Template to output $myColors in an un-ordered list

    <ul>
    {foreach $myColors as $color}
        <li>{$color}</li>
    {/foreach}
    </ul>
    The above example will output:

    <ul>
        <li>red</li>
        <li>green</li>
        <li>blue</li>
    </ul>

    ----------------------------------------------------------

    Example 7.31. Demonstrates the an additional key variable


    <?php
    $people = array('fname' => 'John', 'lname' => 'Doe', 'email' => 'j.doe@example.com');
    $smarty->assign('myPeople', $people);
    ?>

    Template to output $myArray as key/value pairs.


    <ul>
    {foreach $myPeople as $value}
       <li>{$value@key}: {$value}</li>
    {/foreach}
    </ul>

    The above example will output:


    <ul>
        <li>fname: John</li>
        <li>lname: Doe</li>
        <li>email: j.doe@example.com</li>
    </ul>

    -------------------------------------------------------

    Example 7.33. Database example with {foreachelse}

    <?php 
      include('Smarty.class.php'); 
    
      $smarty = new Smarty; 
    
      $dsn = 'mysql:host=localhost;dbname=test'; 
      $login = 'test'; 
      $passwd = 'test'; 
    
      // setting PDO to use buffered queries in mysql is 
      // important if you plan on using multiple result cursors 
      // in the template. 
    
      $db = new PDO($dsn, $login, $passwd, array( 
         PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true)); 
    
      $res = $db->prepare("select * from users"); 
      $res->execute(); 
      $res->setFetchMode(PDO::FETCH_LAZY); 
    
      // assign to smarty 
      $smarty->assign('res',$res); 
    
      $smarty->display('index.tpl');?>
    ?>

    {foreach $res as $r} 
      {$r.id} 
      {$r.name}
    {foreachelse}
      .. no results .. 
    {/foreach}
  • 18-11-2010, 18:38:54
    #4
    bu örneklere göre gittim ama veritabanından bir türlü verileri listelemedi gitti.
  • 18-11-2010, 21:00:01
    #5
    sanırım değişken sırlamalarını ters yapıyorsun

    $smarty->assign(smarty değişkeni,php sayfasından yollayacağın değişken);
  • 19-11-2010, 00:29:38
    #6
    metanek adlı üyeden alıntı: mesajı görüntüle
    sanırım değişken sırlamalarını ters yapıyorsun

    $smarty->assign(smarty değişkeni,php sayfasından yollayacağın değişken);
    doğru
    	if($this->cacheddata != "") {
    	$this->cached = true;
    	$vars=unserialize(file_get_contents($this->cachevarfile));
    	$smarty->assign('menu', $vars);
    	}