yii2


Display HAS_MANY relation data in DetailView yii2


I wants to know is it possible to display one to many relation data in detailview. For example a user can have more than one email registered. So is it possible to display all the emails registered by one user in detailview.
I have tried something like below but its not working.
<?= DetailView::widget([
'model' => $model,
'attributes' => [
'id',
'username',
'firstname',
'lastname',
'location',
'is_active:boolean',
[
'label' => 'Emails',
'value' => ArrayHelper::map(
UserEmails::find()
->where(['user_id'=>$model->id])
->orderBy('id')
->asArray()
->all(),
'id', 'email')
],
],
]) ?>
I am getting error anyway but i wants to know is it possible? and what am i doing wrong here??
In DetailView, item's value can be only a value. So you can prepopulate that value.
$email = implode(',',UserEmails::find()->select('email')->where(['user_id'=>$model->id])->orderBy('id')->asArray()->all())
<?= DetailView::widget([
'model' => $model,
'attributes' => [
'id',
'username',
'firstname',
'lastname',
'location',
'is_active:boolean',
[
'label' => 'Emails',
'value' => $emails
],
],
]) ?>

Related Links

unable to install package using composer in yii2
Yii2 - search by latest of hasMany relation
PendalF89/yii2-filemanager upload error. (Call to a member function saveAs() on null)
Yii2-user Dektrium - how to hash password
2amigos Datepicker is not working with AdminLTE in yii2
Custom filter DD for gridview yii2
Cannot update an extension to latest version in yii2
checkboxlist not rendering checkbox checked correctly
Differentiate between Frontend and Backend Logs in DBTarget Yii2
yii2 ActiveData Provider
How to use custom php function to filter in ActiveDataProvider
Yii2 sort object defaultOrder
How to display names instead of id's in GridView Yii2?
yii2 / Migration Not Working
Kartik GridView Yii2 : Toggle data not working in toolbar
yii2 http client request and repsponse

Categories

HOME
ms-access
hp-exstream
fft
dot
google-docs
survey
contact
synchronization
communication
here-api
php-7.1
n-gram
moonmail
evopdf
excel-vba-mac
beyondcompare
samoa
django-cms
paging
jquery-ajaxq
tapestry
microsoft-r
elasticsearch-net
fabric8
grails-3.1
lxd
cloud-code
devextreme
space-complexity
hot-module-replacement
event-driven
serverside-rendering
sharefile
g-code
spring-security-kerberos
nxlog
estimote
scrollable
pango
pnotify
winscp-net
composite-key
ifs
knpmenubundle
mako
mediaelement
visual-c++-2008
removechild
database-optimization
intrusion-detection
phishing
ctest
connect-by
whois
uid
ora-00900
thredds
fouc
browser-bugs
vstest.console.exe
ami
clicktag
xc16
gui-test-framework
cdt
android-nested-fragment
cctv
sgen
reactfx
comexception
mechanize-ruby
ivyde
flash-builder4.5
e4x
nsnetservice
rdoc
multipage
viewswitcher
enter
jquery-ui-layout
spring-portlet-mvc
asyncfileupload
infobox
android-sdk-2.1
lpeg
wise
fixed-width
database-management
boost-smart-ptr
project-hosting
thread-local-storage
spec#
ajax-forms
document-conversion

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App