logo
down
shadow

yii2 getting data from two models and presenting it in view


yii2 getting data from two models and presenting it in view

Content Index :

yii2 getting data from two models and presenting it in view
Tag : yii2 , By : user184406
Date : November 28 2020, 11:01 PM

hope this fix your issue Assuming that your Pictures has a relation one to one with Users the you can add to you Pictures model a function
class Pictures extends ActiveRecord
{
    // ...

    public function getUser()
    {
        return $this->hasOne(Users::className(), ['id' => 'user_id']);
    }
}
$pictureModel = Pictures::find()->where(['id'=>123])->one();
$userModel= $pictureModel->User;
$picturesModels= Pictures::find()->all();

$userModel = $picturesModels[0]->user
$picturesModels= Pictures::find()->all();

foreach( $picturesModels as $key => $value ) {

  echo $value->user->your_att;  
}

Comments
No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

Yii2 render two models in one view


Tag : yii2 , By : delphiace
Date : March 29 2020, 07:55 AM
With these it helps Yii is the best but I'm have two models , book and author . I need to process two forms for each one in a single view , as I do this in yii2.0 . , try this way
In your Controller
$modelBook = Book::findOne($id);
$modelAuthor  = Author::findOne($key);


  return $this->render('_formWithTheTwoForm', 
           'modelBook' => $modelBook, 
                  'modelAuthor' => $modelAuthor,]);  

Rendering two models in View yii2


Tag : php , By : user160048
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further I am trying to render two models in the actionView method, but without result. Checked some answers on previous questions and it seems my method is OK, but still do not work. , Try using:
<div class="post-view">

    <div class="content">
        <div class="row">
            <div class="col-md-3">
              <?= $model->content; ?>
             <?= $author->username; ?>
          </div>
        </div>
    </div>

</div>

Yii2 - using 2 models in 1 view


Tag : php , By : PaulPlum
Date : March 29 2020, 07:55 AM
With these it helps do the fact you already have function for relation you could add a getter for the related field you neeed eg for company name you could add this function in you Facturen model
  /* Getter for Company name  name */
  public function getCompanyName() {
      return $this->company->company_name;
  }
<?= DetailView::widget([
        'model' => $model,
        'modelProducten' => $modelProducten,
        'attributes' => [
            'factuur_id',
            'companyName',
            'date',
        ],
    ]) ?>

Yii2: how to use two models in one view?


Tag : php , By : Yohan Lee
Date : March 29 2020, 07:55 AM
Hope this helps You need to pass the variable modelCountry to your view files
In your controller action:
    return $this->render('create', [
        'model' => $model,
        'modelCountry' => $modelCountry,
    ]);

View not presenting properly on iPhone plus models


Tag : ios , By : Daniel Reslie
Date : March 29 2020, 07:55 AM
hop of those help? In iPhone 7 simulator, I have a view called cartView which looks like so... , you need to set constraints when you add subview, in this case.
containerView.addSubview(toVC.view)
extension UIView{
     public func attachTo(view : UIView, animated : Bool = true){

            if(animated){
                self.alpha = 0
            }
            else{
                self.alpha = 1
            }

            view.addSubview(self)
            // self.frame = view.bounds

            self.translatesAutoresizingMaskIntoConstraints = false
            self.topAnchor.constraint(equalTo: self.superview!.topAnchor).isActive = true
            self.bottomAnchor.constraint(equalTo: self.superview!.bottomAnchor).isActive = true
            self.leadingAnchor.constraint(equalTo: self.superview!.leadingAnchor, constant: 0).isActive = true
            self.trailingAnchor.constraint(equalTo: self.superview!.trailingAnchor, constant: 0).isActive = true


            if(animated){
                UIView.animate(withDuration: 0.3, animations: {
                    self.alpha = 1
                })
            }
        }
}
Related Posts Related QUESTIONS :
shadow
Privacy Policy - Terms - Contact Us © scrbit.com