开发者

Drupal preprocess function and session

I set a session var at template preprocess function in a theme I use, but the first time I open the site I cant read the session var, if I refresh the page it works fine, anybody know what can be the problem??

This is the code I use in the preprocess function:

function m_preprocess(&$vars, $hook) {
     $default_location = array(
        'country_code' => 'ec',
        'province_code' => 'p',
        'province' => 'Pichincha',
        'city' => 'Quito',
        'city_path' => 'lugares/u/ec/p/*'
     );
     if (isset($_COOKIE['proximity_path'])) $default_location['proximity_path'] = $_COOKIE['proximity_path'];
     $default_location['path'] = iss开发者_如何学Pythonet($_COOKIE['sort-by']) && $_COOKIE['sort-by']=='proximity'? $_COOKIE['proximity_path'] : $default_location['city_path'];
     $_SESSION['location'] = $default_location;
}


A couple of things:

  1. Try dsm($_SESSION); to see what is the var content when the site first load.

  2. I don't know where you create $_COOKIE['proximity_path'], but it is not in the code you show.

  3. Check for typos


The template pre-process function is called before node.tpl.php (that's why it is called pre-process) and that is why the value of the $_SESSION variable is not available in the template preprocess function.

Like you pointed out, it works after the first page load. This happens when only after $_SESSION variable is set in the node body (using the PHP filter)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜