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

Error when trying install yii2-date-picker-widget
Login on advanced template with frontend and backend
Why does CSRF get validated when executing console command in Yii2
Yii2: Add 'user_id' when create a post
output of active view depends on the type of user
How to set-up different URLs for yii frontend and backend
Ecommerce/Classified template with Yii2
Yii2 field accessed only via magic method
How to add a css class to <td> tags in a kv- GridView class in Yii2
Capcha always show incorrect
Integration Reportico in Yii2 Projects
Yii2 : Subdirectory in yii2 not working
Yii2 KCFinder with CKEditor
Yii2 - validation compare acting strange
Updating composer throws exception Class Fxp\Composer\AssetPlugin\Repository\NpmRepository does not exist
Dynamic declaration of a model in Yii2

Categories

HOME
yii2
kde
lodash
youtube-dl
razor
convolution
vifm
mapserver
apache-cayenne
gz
ups
clearcase-ucm
seaborn
jtextfield
conemu
one-hot-encoding
riot.js
ehcache
chromium-embedded
javacv
filezilla
linkerd
jspm
windowbuilder
catel
lxd
hybridauth
openoffice.org
form-data
wpf-controls
host
http-digest
dosbox
simplexml
objectlistview
vapor
lumberjack
dynamic-reports
vao
flashair
btrace
auto-update
scrollable
appcompat
revapi
zip4j
dds
multipeer-connectivity
mu
mplayer
recursive-datastructures
angular-cache
libpng
vmware-tools
adxstudio-portals
autorest
clang-static-analyzer
connect-by
apachebench
xpath-1.0
prerequisites
quicklisp
embedded-code
map-projections
proj4js
c++03
javax.mail
typekit
ng-animate
google-style-guide
client-side-templating
rdl
android-radiobutton
eol
starcluster
fluentautomation
jquery-layout
hyprlinkr
tws
file-locking
shellexecute
dataadapter
mylyn
type-equivalence
robotics-studio
selected
itmstransporter
datawindow
qtkit
hgsubversion
php-parser
stage
android-sdk-2.1
ext3
fixed-width
kdbg
javap
data-driven
temporal-database
yagni
gacutil

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