簡體   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