2016-01-06 24 views
0

獲取客戶名補充說:$data['customer_firstname'] = $this->customer->getFirstName();header.phpOpencart的2.1 - 在header.tpl

你可能是東西:名稱,如在header.tpl

<?php 
class ControllerCommonHeader extends Controller { 
    public function index() { 

     $data['customer_firstname'] = $this->customer->getFirstName(); 

顯示:<?php echo $customer_firstname ?>

登錄到您的店鋪經理:進入擴展,修改和升級(按鈕右上角)。

準備就緒!

回答

1

嘗試這樣的:

獲取客戶信息:

<?php 
class ControllerCommonHeader extends Controller { 
    public function index() { 
     $customer_info = $this->model_account_customer->getCustomer($this->customer->getId()); 
     $data['customer_firstname'] = $customer_info['firstname']; 
+0

這個代碼在歡迎文件中打招呼像歡迎...... –

+0

並嘗試不起作用,該文件,我應該把這個代碼的哪個部分? –

+0

讓我編輯它。 –

0

被引用後使用

$data['customer_firstname'] 

你應該把你的變量在$數據數組將它傳遞給模板...

+0

你可以更好地解釋這一點。 –

+0

請閱讀您提到的鏈接線索,並查看接受的答案。他們使用「$ data ['customer_lastname'] = $ this-> customer-> getLastName();」我可以假設$ data只是傳遞給模板。在.TPL內部,您可以訪問這些值而不指向$ data。 – campino2k

+0

此頁面旨在幫助您解決問題。這不是「我們寫你的代碼,所以你可以複製粘貼這個」的東西。 – campino2k

0

添加:$data['customer_firstname'] = $this->customer->getFirstName();header.php

您可能是一些:

<?php 
class ControllerCommonHeader extends Controller { 
    public function index() { 

     $data['customer_firstname'] = $this->customer->getFirstName(); 

顯示例如在header.tpl名稱:<?php echo $customer_firstname ?>

登錄到你的店經理:去擴展,修改和升級(按鈕右上)。

準備就緒!

1

OpenCart項目中有兩個header.tpl文件。我認爲你是在public_html/catalog/controller/common/header.tpl裏面編輯header.tpl,所以沒有什麼能解決你編輯這個文件的問題。

轉到第二個header.tpl文件所在的其他位置。你可以在public_html/system/storage/modify/catalog/controller/common/header.tpl中找到它。在那裏你可以通過添加這些值來獲得值,

$data['customer_firstname'] = $this->customer->getFirstName(); 
    $data['customer_lastname'] = $this->customer->getLastName(); 

這將解決你的問題。