I have two custom fields in my customer table, namely nickname and sponsor. I would like to create an sql query to select the two custom fields that I have in the table. What kind of query should I do?
-
in magento1 or magento2 and what is table name ?Ansar Husain– Ansar Husain2018年08月16日 05:02:17 +00:00Commented Aug 16, 2018 at 5:02
-
Itś Magento 2 and the name of the table is 'mgfx_customer_entity'Nuno Sousa– Nuno Sousa2018年08月16日 05:27:15 +00:00Commented Aug 16, 2018 at 5:27
-
Why you dont need to use repository or collection its eav entity its not simple to get with sql query and its not recomendedMohamed El Mrabet– Mohamed El Mrabet2018年08月16日 05:59:45 +00:00Commented Aug 16, 2018 at 5:59
-
Só, how can I do it? I’m a newbieNuno Sousa– Nuno Sousa2018年08月16日 06:05:24 +00:00Commented Aug 16, 2018 at 6:05
1 Answer 1
You can use in your phtml file where you need .
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$customers = $objectManager->create('Magento\Customer\Model\ResourceModel\Customer\Collection')->load();
foreach($customers as $customer){
echo $customer->getNickname();
echo $customer->Sponsor();
}
or you can get these value by block using module like as
<?php
namespace Vendor\Module\Block;
use Magento\Framework\View\Element\Template;
class Customer extends Template
{
protected $customerFactory;
public function __construct(
\Magento\Customer\Model\CustomerFactory $customerFactory,
)
{
$this->customerFactory = $customerFactory;
}
public function getCustomerCollection(){
$collection=$this->customerFactory->create()->getCollection();
return $collection;
}
}
And add below code in phtml file inside that module
$customers=$block->getCustomerCollection();
foreach($customers as $customer){
echo $customer->getNickname();
echo $customer->Sponsor();
}
answered Aug 16, 2018 at 6:14
Ansar Husain
3,4791 gold badge15 silver badges32 bronze badges
default