智能缓存和登录状态 [英] smarty cache and login states

查看:97
本文介绍了智能缓存和登录状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在想。你们如何处理网站的登录和登出状态在顶部的情况。因此,如果有人登录,则说 Hello Scott。如果有人未登录,则会显示登录。

I was wondering. How do you guys deal with scenario of website where you have login and log out states at the top. So if someone is logged in, you say "Hello Scott". If someone's not logged in, it says "Log In".

我正在使用force compile = false。并使用

I am using force compile = false. And using

(!$smarty->is_cached('index.tpl',$template_cache_id)) {
 do something
}

你们用什么来保持某些部分不被缓存而另一些被缓存对于这种常见情况?我的网站是 photoidentify.com

What do you guys use to keep some sections not cache and others cached for such a common scenario? My site is photoidentify.com

谢谢! / p>

Thanks!

推荐答案

我定义了一个块函数,该函数将从高速缓存中排除模板的小块。

I have defined a block function that excludes small blocks of the templates from cache.

function smarty_block_dynamic($param, $content, $smarty) {
    return $content;
}

$smarty->register_block("dynamic", "smarty_block_dynamic", false);

因此,模板中由{dynamic} {/ dynamic}包围的所有内容均不会被缓存。这样就可以输出基于会话的数据,例如已登录的用户名等。

Thus, anything in the template surrounded by {dynamic}{/dynamic} will not be cached. This allows for the output of, for example, session based data such as the logged in user name et cetera.

这篇关于智能缓存和登录状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆