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

How to remove an asset from a particular view in yii2
How to specify alias for multiple join with same table?
Yii2 UUID not mapped with model value
Yii2 Pjax on ActiveForm and GridView [ Got it Working]
Yii2 - how to get the selected value from DepDrop
How to use models from different domain in frontend's site controller?
frontend login is not working properly in yii2
Yii Gridview show/hide columns from interface when filtering the records
Yii2 skip to other URL route if <controller>/<action> is not found
Include additional library to yii2
Yii2 make session works on all actions of one controller?
Yii2 display data from phpexcel in view before saving to database
yii2 dependant dropdown reset on edit action due to onchange function
Yii2 non-DB (or virtual) attribute isn't populated during massive assignment?
Yii2 Join multiple tables
Codeception Adding custom assert actions (functional testing)

Categories

HOME
wso2-am
fluentd
react-virtualized
view
include
stock
setup-deployment
maven-3
jgroups
django-imagekit
session-variables
windows-10-universal
vifm
volttron
spring-xd
windows-azure-storage
ibm-odm
decimal
jsprit
saxon
windows-7-x64
evopdf
connection-string
excel-vba-mac
crystal-reports-2008
firefox-webextensions
format-specifiers
claims-based-identity
dynamic-featured-image
virtualdub
filezilla
xacml
iframe-resizer
galsim
karaf
subset-sum
http-referer
amazon-kinesis-kpl
mapbox-gl
bower-install
multilingual
libvpx
withings
sharefile
azure-ml
fedex
ruby-on-rails-3.1
no-www
netcdf4
acoustics
scrollable
pango
logparser
clean-architecture
domain-model
hls.js
elgg
brightcove
python-cryptography
gnome-shell-extensions
pintos
jquery-filter
slicknav
multi-level
mikroc
storekit
gstreamer-0.10
flash-cs5
ready-api
livequery
goose
ios8-today-widget
msys
intel-fortran
teamcity-8.0
unity3d-gui
umbraco6
system.reflection
website-monitoring
coldbox
android-nested-fragment
responsive-slides
rtmfp
html5-notifications
industrial
opcache
shellexecute
jquery-mobile-dialog
pygit2
trusted
venn-diagram
propertyeditor
pysimplesoap
reddot
bigcouch
nsobject
gdlib
html-input
zend-translate
sortable-tables
dentrix
meego
web-architecture
port-number
spec#
mediarss
commodore
paul-graham

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