【问题标题】:Yii - Unexpected logout link in the viewYii - 视图中的意外注销链接
【发布时间】:2013-01-11 10:32:38
【问题描述】:

欢迎。

我有一个奇怪的情况,因为我的 Yii 框架本身会生成用于注销的链接并将其放在每个元素(span、div、li 等)的视图主体中 由于这个问题,每次点击视图主体时,我都会注销

为了生成视图,我使用了 $this->render();

结果 DOM 如下所示:

<section class="top-line">
    <div class="right">
         <a href="/workflow/?r=user/logout"> </a>
    </div>
    <a href="/workflow/?r=user/logout"> </a>
</section>
<a href="/workflow/?r=user/logout">
  <div class="main-box">...</div>
</a>

<footer>
<a href="/workflow/?r=user/logout"> </a>
<div class="container">..</div>
</footer>

@DarkMukke 包含 layouts/main.php:

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="language" content="en" />
    <link rel="shortcut icon" href="<?php echo Yii::app()->request->baseUrl; ?>/favicon.ico" type="image/x-icon" />
    <!-- blueprint CSS framework -->
    <link rel="stylesheet" type="text/css" href="<?php echo baseUrl(); ?>/css/screen.css" media="screen, projection" />
    <link rel="stylesheet" type="text/css" href="<?php echo baseUrl(); ?>/css/print.css" media="print" />
    <!--[if lt IE 8]>
    <link rel="stylesheet" type="text/css" href="<?php echo baseUrl(); ?>/css/ie.css" media="screen, projection" />
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="<?php echo baseUrl(); ?>/css/form.css" />
    <link rel="stylesheet" type="text/css" href="<?php echo baseUrl(); ?>/css/blue/style.css" />

    <?php
    $cs = cs();
    $cssCoreUrl = $cs->getCoreScriptUrl();
    $cs->registerCssFile($cssCoreUrl . '/jui1.9.2/css/base/jquery-ui.css');
    $cs->registerCoreScript('jquery');
    $cs->registerCoreScript('jquery.ui');
    $cs->registerCoreScript('cookie');
    $cs->registerScriptFile('js/block.js');
    $cs->registerScriptFile('js/global.js');
    $cs->registerScriptFile('css/blue/style.js');
    ?>

    <title><?php echo CHtml::encode($this->pageTitle); ?></title>
</head>
<body>

    <header class="top">
        <div class="container">
            <div class="logo">
                <h1><a href="<?php echo Yii::app()->baseUrl; ?>" ><?php echo CHtml::encode(Yii::app()->name); ?></a></h1>
            </div>
            <nav>
                <?php $this->widget('Menu'); ?>
            </nav>
        </div>
    </header>

    <section class="top-line">
        <div class="container">
            <?php if (isset($this->breadcrumbs)): ?>
                <div class="left">
                    <?php
                    $this->widget('zii.widgets.CBreadcrumbs', array(
                        'links' => $this->breadcrumbs,
                    ));
                    ?>
                </div>
            <?php endif ?>
            <?php if (Yii::app()->user->isGuest == false): ?>
                <div class="right">
                    <a href="<?php echo url('/user/logout'); ?>"><?php echo t('Logout') . ' (' . Yii::app()->user->name . ')'; ?>
                </div>
            <?php endif; ?>
        </div>
    </section>

    <div class="main-box">
         <div class="container clear">
                <div class="clear cenetr">
                    <?php
                    foreach (Yii::app()->user->getFlashes() as $key => $message) {
                        echo '<div class="flash-' . $key . '">' . $message . " <span class=\"close-flush-btn\"></span></div>\n";
                    }
                    ?>
                </div>
        </div>
        <div class="wrapper">
            <?php echo $content; ?>
        </div>
    </div>
    <footer>
        <div class="container">
            <div class="wrapper">
                <div class="fleft"><?php echo Yii::app()->params['copyrightInfo']; ?></div>
                <div class="fright"><?php echo Yii::powered(); ?></div>
            </div>
        </div>
    </footer>
</body>

有人遇到过这个问题吗?此类行为可能导致。

[已解决] 我的愚蠢错误。不要在注销链接中关闭标签,并且正文会在每次点击时做出反应。真可惜.. 感谢您的关注。

【问题讨论】:

  • 你能发布你的 /protected/views/layout/main.php 吗?
  • 那些'block.js'和'global.js'脚本是什么?我认为注销链接是在客户端添加的(通过 JavaScript),而不是在服务器端(通过 Yii)。

标签: yii


【解决方案1】:

你的标签里面有你的主框

将其用作最后 3 行,否则每次单击主框都不会触发元素

<a href="/workflow/?r=user/logout"> </a>
<div class="main-box">
</div>
【解决方案2】:

您希望未登录用户可以使用的内容,请使用

if (Yii::app()->user->isGuest){
echo 'your content';
}

登录用户的内容

if (!Yii::app()->user->isGuest){
echo 'your content';
}

如果可行,现在让我来。如果没有,你的 UserIdentity 类有问题

【讨论】:

  • 没有区别,我把视图放在注册用户的子句中,一切都显示了,但注销链接一直存在。 Wrog Identy Class 可能是一个很好的线索.. 我会检查
  • var_dump(Yii::app()->user) 在这两种情况下的输出是什么? (当您登录和未登录时)
  • 完全一样的东西,很奇怪
  • 我可以看看你的 UserIdentity 类吗?你确定你是登录用户吗?
猜你喜欢
  • 2014-12-04
  • 1970-01-01
  • 1970-01-01
  • 2015-02-06
  • 1970-01-01
  • 2017-08-22
  • 1970-01-01
  • 2012-02-15
  • 2012-09-17
相关资源
最近更新 更多