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

Yii2 full calendar AjaxEvents not working properly
white color Issue after create thumbnail image in yii2
Creating a one-to-many relationship in Yii2
Handle Image update in yii2
Header and Footer missing in modal popup
Select2 Krajee widget - using modal and getting the id of the value
sjaakp/yii2-illustrated-behavior Yii2 extension for image not working
change the navigation bar url from yii2 without redirecting
Yii 2 - Conditional Assets?
How to get value of dropdown instead of id yii2
How can I access private value from object
How to add valueless attribute to <form> tag using yii2 ActiveForm
Register a js file independently in Assets
Get user's email from twitter login in yii2
get Attribute Label in yii2
Yii 2 code formater to display xml with code highlighting in html, string highlighter

Categories

HOME
google-chrome-extension
listview
netbeans
magnific-popup
activiti
cplex
amazon-ecs
v8
flyway4
autotools
awesome-wm
google-translate
here-api
rascal
qt-creator
remote-access
dosgi
apache-metamodel
excel-vba-mac
nhibernate-envers
google-pagespeed
clickonce
tibco-mdm
buildbot
semantic-analysis
kannel
info.plist
bootstrap-material-design
fopen
publish
typo3-6.2.x
assistant
elasticsearch-net
unboundid
flink-streaming
copying
protovis
http-referer
hexo
adobe-premiere
xcode-extension
fakeiteasy
bootstrap-dialog
sencha-touch-2.3
angular2-meteor
appcompat
zip4j
fancybox-2
pdfclown
sqldf
gnome-shell-extensions
visual-c++-2008
ableton-live
angular-cache
grails-tomcat-plugin
httplistener
radtreelist
probability-density
lua-5.1
master-slave
sdf
captivenetwork
nessus
system.management
photobucket
lemon
atk4
computer-algebra-systems
remobjects
apache-commons-net
npapi
modalpopup
codeigniter-url
cdt
rdtsc
heisenbug
rebol3
jboss-weld
app42
java.nio.file
easy-install
mylyn
xamlparseexception
tridion-worldserver
regsvr32
php-parser
floating
zend-translate
webkit.net
scripting-languages
grid-system
caching-application-block

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