Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/297.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 无论用户是否登录,$logged都返回1_Php_Smarty_Prestashop - Fatal编程技术网

Php 无论用户是否登录,$logged都返回1

Php 无论用户是否登录,$logged都返回1,php,smarty,prestashop,Php,Smarty,Prestashop,我像这样向smarty添加了$logged变量,以检查用户是否登录 $this->smarty->assign(array( 'wppopup' => $wppopup, 'logged' => $this->context->customer->isLogged(), 'default_lang'

我像这样向smarty添加了$logged变量,以检查用户是否登录

$this->smarty->assign(array(      
                    'wppopup' => $wppopup,  
                    'logged' => $this->context->customer->isLogged(),          
                    'default_lang' => (int)$this->context->language->id,
                    'image_width' => Configuration::get('WPPOPUP_IMAGE_WIDTH'),
                    'image_height' => Configuration::get('WPPOPUP_IMAGE_HEIGHT'),
                    'id_lang' => $this->context->language->id,
                    'wppopup_image' => !Configuration::get('WPPOPUP_IMAGE_DISABLE') && file_exists('modules/wppopup/wppopup_image_'.(int)$id_shop.'.jpg'),
                    'image_path' => $this->_path.'wppopup_image_'.(int)$id_shop.'.jpg'
                )
        );
但是当我在模板文件中使用它
{if$logged}
时,它返回空。其他变量运行良好

有什么东西不见了吗?

这样试试看

if($this->context->customer->isLogged() == true){
    $isLogged = "true";
}else{
    $isLogged = "false";
}

$this->smarty->assign(array(
    'wppopup' => $wppopup,  
    'logged' => $isLogged,  
    'default_lang' => (int)$this->context->language->id,
    'image_width' => Configuration::get('WPPOPUP_IMAGE_WIDTH'),
    'image_height' => Configuration::get('WPPOPUP_IMAGE_HEIGHT'),
    'id_lang' => $this->context->language->id,
    'wppopup_image' => !Configuration::get('WPPOPUP_IMAGE_DISABLE') && file_exists('modules/wppopup/wppopup_image_'.(int)$id_shop.'.jpg'),
    'image_path' => $this->_path.'wppopup_image_'.(int)$id_shop.'.jpg')
);

这不是一个聪明的问题。您应该签入PHP文件,在该文件中,您希望将
isLogged
方法返回的值分配给“logged”

使用简单

var_dump($this->context->customer->isLogged());
以确保此方法返回哪些值,以便您可以进行检查

当我在PHP中使用

$smarty->assign(array(                          
                    'logged1' => true,        
                    'logged2' => false
                )
        );
在Smarty文件中:

{if $logged1}
is logged
{/if}

{if $logged2}
is logged too
{/if}
输出为

被记录


所以,如果您将简单的true和false分配给Smarty变量,它会正常工作,因此isLogged方法可能会返回一些其他值。

它不会更改任何内容。为什么要分配字符串true和false而不是bool?我尝试了,$logged返回1,即使用户登录或未登录,我该怎么办?你是说
var\u dump($this->context->customer->isLogged())总是给你1,即使用户没有登录?$this->context->customer->isLogged()和var_dump($this->context->customer->isLogged())都给1。我想我得到了,这是关于缓存的,我如何禁用缓存?我不知道你说的缓存是什么意思。您可能应该查看您的Prestashop文档来完成这项工作。