1
1 개보기에서이 개 모델을 사용하지만 추가 한 필드는 "(설정되지 않음) '하지만 그들은 deffinetly 그래서 내가 무슨 짓을했는지 잘못 데이터베이스에 설정하고Yii2 - 나는 1 개보기에서이 개 모델을 사용하여 시도
당신이 어떤 추가 코드가 필요하면 그냥 내가 그것을 제공하는 것 물어<?php
use yii\helpers\Html;
use yii\widgets\DetailView;
use app\models\Facturen;
/* @var $this yii\web\View */
/* @var $model app\models\Facturen */
/* @var $modelProducten app\models\Producten */
$this->title = $model->factuur_id;
$this->params['breadcrumbs'][] = ['label' => 'Factures', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="facturen-view">
<h1><?= Html::encode($this->title) ?></h1>
<p>
<?= Html::a('Update', ['update', 'id' => $model->factuur_id], ['class' => 'btn btn-primary']) ?>
<?= Html::a('Delete', ['delete', 'id' => $model->factuur_id], [
'class' => 'btn btn-danger',
'data' => [
'confirm' => 'Are you sure you want to delete this item?',
'method' => 'post',
],
]) ?>
</p>
<?= DetailView::widget([
'model' => $model,
'modelProducten' => $modelProducten,
'attributes' => [
'factuur_id',
'company.company_name',
'person.first_name',
'product.product_id',
'product.product_name',
'product.amount',
'product.price',
'date',
],
]) ?>
</div>
also the create code might be usefull
public function actionCreate()
{
$model = new Facturen();
$modelProducten = [new Producten];
if ($model->load(Yii::$app->request->post())) {
$transaction = Yii::$app->db->beginTransaction();
$success = true;
$modelProducten = Model::createMultiple(Producten::classname());
Model::loadMultiple($modelProducten, Yii::$app->request->post());
if ($model->save()) {
foreach($modelProducten as $modelProduct) {
$modelProduct->factuur_id = $model->factuur_id;
if (! $modelProduct->save()) {
$success = false;
break;
}
}
} else {
$success = false;
}
if ($success) {
$transaction->commit();
return $this->redirect(['view', 'id' => $model->factuur_id]);
} else {
Yii::$app->session->setFlash('danger', 'Kan niet opslaan, validate errors');
}
}
return $this->render('create', [
'model' => $model,
'modelProducten' => (empty($modelProducten)) ? [new Producten] : $modelProducten
]);
}
: 여기
Here you see the result of the added fields 뷰 코드입니다!
희망 너희들은 문제를 이해하고
~ 편집 ~
@Gunnrryy
the relations are here 또한 사람이 totaly 잘 작동 단지 "PRODUCTEN"필드 돈을 '나를 도울 수 있습니다 t 작업
Facturen 모델 코드
<?php
namespace app\models;
use Yii;
/**
* This is the model class for table "facturen".
*
* @property integer $factuur_id
* @property string $date
* @property integer $company_id
* @property integer $person_id
*
* @property Companies $company
* @property Spokepersons $person
* @property Producten[] $productens
*/
class Facturen extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'facturen';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['date', 'company_id', 'person_id'], 'required'],
[['date'], 'string', 'max' => 64],
[['company_id', 'person_id'], 'integer'],
[['company_id'], 'exist', 'skipOnError' => true, 'targetClass' => Companies::className(), 'targetAttribute' => ['company_id' => 'company_id']],
[['person_id'], 'exist', 'skipOnError' => true, 'targetClass' => Spokepersons::className(), 'targetAttribute' => ['person_id' => 'person_id']],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'factuur_id' => 'Factuurnummer',
'date' => 'Factuurdatum',
'company_id' => 'Bedrijfsnaam',
'person_id' => 'Contactpersoon',
];
}
/**
* @return \yii\db\ActiveQuery
*/
public function getCompany()
{
return $this->hasOne(Companies::className(), ['company_id' => 'company_id']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getPerson()
{
return $this->hasOne(Spokepersons::className(), ['person_id' => 'person_id']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getProduct()
{
return $this->hasMany(Producten::className(), ['factuur_id' => 'factuur_id']);
}
}
,
아마도 DetailView 위젯의 modelProducten이 잘못되었습니다. modelProducten과 Facturen 사이에 어떤 관련이 있습니까? 그렇다면 관계를 통해 관계를 통해 사용하십시오. 예를 들어, company.company_name – Gunnrryy
을 사용하면 모델에 관계자가 없기 때문에 모델 관계를 표시 할 수 있습니다. – Gunnrryy
귀하의 모델에서 @Gunnrryy –