smarty cache and login states

亡梦爱人 提交于 2019-12-14 03:54:22

问题


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".

I am using force compile = false. And using

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

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

Thanks!


回答1:


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);

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.



来源:https://stackoverflow.com/questions/1415859/smarty-cache-and-login-states

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!