Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Smarty Cache Problem

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Language: German
View previous topic :: View next topic  
Author Message
NiRu
Smarty n00b


Joined: 22 Jun 2013
Posts: 3

PostPosted: Sat Jun 22, 2013 9:33 am    Post subject: Smarty Cache Problem Reply with quote

Hallo gemeinsam,

Ich stehe vor einem recht blöden Problem mit Smarty, und hoffe jemand weiß woran das liegen könnte. Vorab ich verwende Smarty Version 3.1.13.

In meinem derzeitigen Projekt verwende ich den cache und eigentlich habs auch bisher keine Probleme doch jetzt folgendes, wenn der cache deaktiviert ist funktioniert folgendes Beispiel:
Code:

public function loginAction() {
        $view = View::getInstance();
        $account = new Account($this->getCarrierEntry('Database'));

        if (isset($_POST['username']) and isset($_POST['password'])) {
           
            if ($account->login($_POST['username'], $_POST['password'])) {
                if (isset($this->redirected_url))
                    $this->Redirect($this->redirected_url);
                else
                    $this->Redirect($this->getRouter()->BuildRoute('home'));

                return;
            } else {
                // Login fehlgeschlagen
                $view->assign('login_failed', 'Login fehlgeschlagen', true);
            }

            $view->assign('posturl', $this->getRouter()->BuildRoute('user_login'), true);
            $view->display('Account/Login.tpl');
            return;
        }


        // Zeige Login Template
        $view->assign('posturl', $this->getRouter()->BuildRoute('user_login'));
        $view->display('Account/Login.tpl');
    }


Smarty Template:
Code:

{extends file="Layout/Layout_page_wohi.tpl"}

{block "content"}
    <div class="pxholder25"></div>
    <div class="login-content">
        <h4>Einloggen</h4>
        <form method="POST" action="{$posturl}">
            <label>Benutzername</label>
            <input name="username" class="input-block-level" type="text">
            <label>Passwort</label>
            <input name="password" class="input-block-level" type="password">
            <input class="btn" type="submit" value="Einloggen">
        </form>
        {if isset($login_failed)}
            Warum macht smarty nichts :(
        {/if}
        <ul>
            <li><a href="#">Passwort vergessen?</a></li>
            <li><a href="#">Du hast noch keinen Account?</a></li>
        </ul>
    </div>
{/block}

(Die doppelte display methode war nur zum aufspüren des Fehlers, die kommt später wieder raus Smile )

Ist der cache aber aktiv überspringt er jedoch alle neuen Abfragen, obwohl bei der einzelnen Variable $login_failed der nocache Parameter auf true gesetzt wurde. bei aktiven cache wird dir Variable aber in der Smarty Debug Console angezeigt.

Nun hoffe ich jemand weiß was dagegen getan werden kann.
Vielen Dank!
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Sat Jun 22, 2013 10:56 am    Post subject: Reply with quote

Ohne jetzt Deinen Kode näher angeschaut zu haben...

Wenn Du den Status vom nocache Parameter in $smarty->assign(..) änderst musst du manuell dafür sorgen das die Template neu compiliert werden. (Cache und Compiled Templates löschen).
Back to top
View user's profile Send private message
NiRu
Smarty n00b


Joined: 22 Jun 2013
Posts: 3

PostPosted: Sat Jun 22, 2013 2:06 pm    Post subject: Reply with quote

Hallo, danke für die schnelle Antwort.

Ich dachte der assign nocache parameter löst automatisch aus das die Variable die den Wert true erhält automatisch nicht aus dem Cache geladen wird. Ich habe den Cache immer Manuel gelöscht, gibts da irgend einen Trick, ich würde ungern den gesamten Cache immer für den Login leeren lassen.

Danke!
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Sat Jun 22, 2013 2:37 pm    Post subject: Reply with quote

Das Problem ist noch weiter vorgelagert.

Für eine Variable mit nocache muss anderer Kode kompiliert werden.
Wenn Du vorher mit einer Variablen mit $smarty->assign('foo','bar',false) gearbeitet hast und änderst Dein Script dann auf $smarty->assign('foo','bar',true) dann müssen die Templates neu kompiliert werden. Diese Situation wird aber von Smarty nicht automatisch erkannt.
Du musst dann nach Änderung des Scriptes auch die existierenden compilierten Templates im template_c und cache Verzeichniss löschen.
Dieses ist nur einmalig nach Änderung des PHP Scripts notwendig.
Siehe dazu auch http://www.smarty.net/docs/en/caching.cacheable.tpl#cacheability.variables

Dieses Problem tritt nicht auf, wenn Du im Template {nocache} {/nocache} Bereiche definieren würdest.
Back to top
View user's profile Send private message
NiRu
Smarty n00b


Joined: 22 Jun 2013
Posts: 3

PostPosted: Sat Jun 22, 2013 3:34 pm    Post subject: Reply with quote

Hallo, danke nochmals,
Das mit der Umstellung einer variable auf nocache ist mir auch bereits aufgefallen, seitdem lösche ich nach jeder Änderung den Cache von Hand.

Ich muss vor der $_POST if Abfrage den Smarty den Wert als null mitgeben, und in der der $_POST If dann einen Wert Anhängen, dann kann ich es via {if ($var)} sehen. isset funktioniert aus unerklärlichen Gründen leider nicht.

Nur so funktioniert es:
Code:

$view->assign('login_failed', null, true);
        if(isset($_POST['username']) && isset($_POST['password'])){
            $view->assign('login_failed', 'Login fehlgeschlagen', true);
        }     


//Edit

Vielen Dank noch mal für deinen Beitrag, ich habe lange gebraucht bis ich verstanden habe was du mit den {nocache} gemeint hast.
So funktioniert es um längen besser!

Vielen Dank nochmals!
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Language: German All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP