Php OpenCart 2.1-在header.tpl中获取客户的名字

Php OpenCart 2.1-在header.tpl中获取客户的名字,php,opencart,opencart2.x,Php,Opencart,Opencart2.x,添加:$data['customer_firstname']=$this->customer->getFirstName() 你可能是: <?php class ControllerCommonHeader extends Controller { public function index() { $data['customer_firstname'] = $this->customer->getFirstName(); <?php clas

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

你可能是:

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

        $data['customer_firstname'] = $this->customer->getFirstName();
<?php
class ControllerCommonHeader extends Controller {
    public function index() {

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

登录到您的商店经理:转到扩展、修改和升级(右上角按钮)

准备好了

试试这个:

获取客户信息:

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

获取客户信息:

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

引用的帖子使用

$data['customer_firstname'] 

您应该将变量放入$data数组中,以将其传递到引用的post使用的模板…

$data['customer_firstname'] 

您应该将变量放入$data数组中,以将其传递到模板…

添加:
$data['customer\u firstname']=$this->customer->getFirstName()header.php中的code>

你可能是:

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

        $data['customer_firstname'] = $this->customer->getFirstName();
<?php
class ControllerCommonHeader extends Controller {
    public function index() {

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

登录到您的商店经理:转到扩展、修改和升级(右上角按钮)


准备好了

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

你可能是:

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

        $data['customer_firstname'] = $this->customer->getFirstName();
<?php
class ControllerCommonHeader extends Controller {
    public function index() {

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

登录到您的商店经理:转到扩展、修改和升级(右上角按钮)


准备好了

OpenCart项目中有两个header.tpl文件。我认为您正在public_html/catalog/controller/common/header.tpl中编辑header.tpl,因此没有什么可以解决您编辑此文件的问题

转到第二个header.tpl文件所在的其他位置。您可以在public_html/system/storage/modification/catalog/controller/common/header.tpl中找到它。在这里,您可以通过添加这些

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

这将解决您的问题。

OpenCart项目中有两个header.tpl文件。我认为您正在public_html/catalog/controller/common/header.tpl中编辑header.tpl,因此没有什么可以解决您编辑此文件的问题

转到第二个header.tpl文件所在的其他位置。您可以在public_html/system/storage/modification/catalog/controller/common/header.tpl中找到它。在这里,您可以通过添加这些

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

这将解决您的问题。

而try不起作用,该文件以及我应该将代码放在哪一部分?如果我没有将代码放在哪里,请按照我的建议编辑问题。try不起作用,该文件以及我应该将代码放在哪一部分?按照我的建议编辑问题,如果我没有把代码放在原处。你最好解释一下。请阅读你提到的链接线程,并查看接受的答案。他们使用“$data['customer\u lastname']=$this->customer->getLastName();”,我可以假设$data只传递给模板。在.TPL中,您可以访问值,而无需指向$data。此页面旨在帮助您解决问题。这不是一个“我们写你的代码,所以你可以复制粘贴这个”的事情。我明白,我不想复制粘贴答案,我需要的是帮助我解决问题,尝试你提到的,但不起作用。如果我说中奖彩票号码。。。但不说是哪个国家?你会有所帮助吗?将
$data[“customer\u info”]=$this->model\u account\u customer->getCustomer($this->customer->getId())
放入索引函数,保持header.tpl不变。其实没那么难。你可以更好地解释一下。请阅读你提到的链接帖子,并查看接受的答案。他们使用“$data['customer\u lastname']=$this->customer->getLastName();”,我可以假设$data只传递给模板。在.TPL中,您可以访问值,而无需指向$data。此页面旨在帮助您解决问题。这不是一个“我们写你的代码,所以你可以复制粘贴这个”的事情。我明白,我不想复制粘贴答案,我需要的是帮助我解决问题,尝试你提到的,但不起作用。如果我说中奖彩票号码。。。但不说是哪个国家?你会有所帮助吗?将
$data[“customer\u info”]=$this->model\u account\u customer->getCustomer($this->customer->getId())
放入索引函数,保持header.tpl不变。其实没那么难。