繁体   English   中英

如何使用zend Framework在用户帐户页面中显示用户头像/图像?

[英]How to display the user avatar/image in the user account page using zend framework?

图像由用户上传并存储在public / users文件夹中。 视图脚本如下:

<?php echo $this->render("includes/header.phtml"); ?>
<div id="header">
<div class="w">
    <div id="logo"><a href="/">SyncFan.com</a></div>
    <div id="mainmenu">
        <ul>
            <li class="selected"><a href="/account/accountmanager"><span>My Account</span></a></li>             
            <li onMouseMove="$('.submenu',this).show();$(this).addClass('hover');"  onMouseOut="$('.submenu',this).hide();$(this).removeClass('hover');"><a href="/artist/list"><span>View Artists</span></a></li>
            <li onMouseMove="$('.submenu',this).show();$(this).addClass('hover');"  onMouseOut="$('.submenu',this).hide();$(this).removeClass('hover');"><a href="/account/update"><span>Update Account</span></a></li>
            <li onMouseMove="$('.submenu',this).show();$(this).addClass('hover');"  onMouseOut="$('.submenu',this).hide();$(this).removeClass('hover');">
                <a href="/account/logout"><span>Log Out</span></a>
            </li>
        </ul>
    </div>
</div>
</div>

<div id="content" class="w">
<h2>SyncFan My Page - <?php $this->session = new Zend_Session_Namespace('login');echo $this->escape($this->session->username); ?></h2>
<!--- MAIN CONTAINER -->
<table class="table">
<tr><td valign="top">
<!--PROFILE DATA-->
<table class="table ">
<tr><td>Username: <?php echo $this->session->username; ?></td></tr>
<tr><td><img src="<?php echo '../public/users/'.$this->avatar; ?>"/></td></tr>
<tr><td><?php echo $this->aboutme; ?></td></tr>
<tr><td>Date Joined: <?php echo $this->session->dateJoined?></td></tr>
</table>
</td>
<td valign="top">
<!--FAVORITE ARTIST LIST-->
<table class="table table-hover">
<?php if($this->artists){?>
<tr align="center">
<td><b>Artist Name</b></td>
<td><b>Date Became A Fan</b></td>
</tr>
<?php foreach($this->artists as $artist){?>
<tr>
<td><a href='/artist/video-list?artist=<?php echo
urlencode($artist['artist_name'])?>'>
<?php echo $this->escape($artist['artist_name']); ?></a></td>
<td><?php echo $this->escape($artist['date_became_fan']); ?></td></tr>
<?php }
}else{
?>
<tr><td>You currently have no favorite artists.</td></tr>
<?php }?>
</table>
</td>
</tr>

</table>
</div>
<?php echo $this->render("includes/footer.phtml"); ?>

在帐户视图中。 HTML语句的输出

<img src="<?php echo '../public/users/'.$this->avatar; ?>"/> 

是空的。 我能够获取上载图像的详细信息,但无法将其显示回用户帐户。

<?php var_dump($this->avatar); ?>

以上语句的输出是字符串'filename.jpg'(长度=文件长度)。

我也检查了.htaccess文件,但找不到任何错误。 任何帮助将不胜感激。

<img src"<?php echo '/users/'.$this->avatar;?>"/>

浏览器无法访问文档根目录之外的任何内容(大概是/public ,因此路径应相对于该路径。

编辑 :所以从您的模板的行是:

<tr><td><img src="<?php echo '../public/users/'.$this->avatar; ?>"/></td></tr>

如果查看生成的HTML页面的源,则应获得:

<tr><td><img src="../public/users/filename.jpg"/></td></tr>

(不起作用)。 根据我上面的建议,模板中的行实际上应该是:

<tr><td><img src"<?php echo '/users/'.$this->avatar;?>"/></td></tr>

这应该给你:

<tr><td><img src"/users/filename.jpg"/></td></tr>

如果您实际得到:

<tr><td><img src""/></td></tr>

那么您就错过了“回声”。 如果您得到:

<tr><td><img src"/users/"/></td></tr>

那么$this->avatar实际上并不包含您所说的filename.jpg。

如果整个页面为空白,则实际上是在生成PHP错误,但您已关闭display_errors (请检查您的Web服务器错误日志)。 在不完全知道自己得到什么的情况下,我所能做的只是猜测。

<img src="<?php echo '/users/'.$this->avatar; ?>"/>

.htaccess

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM