Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Undefined offset: 0 #142

Open
strtob opened this issue Apr 30, 2018 · 0 comments
Open

Error: Undefined offset: 0 #142

strtob opened this issue Apr 30, 2018 · 0 comments

Comments

@strtob
Copy link

strtob commented Apr 30, 2018

Hi,

I've generated Models + CRUD Interface, if I try to insert a new record in n:m table I got the following error:

PHP Notice – yii\base\ErrorException
Undefined offset: 0

  1. in /var/www/html/re-exchange/vendor/mootensai/yii2-relation-trait/RelationTrait.php at line 135
    126127128129130131132133134135136137138139140141142143144 $container[] = $relObj;
    }
    }
    $this->populateRelation($relName, $container);
    } else if ($isHasMany) {
    $container = [];
    foreach ($v as $relPost) {
    if (array_filter($relPost)) {
    /* @var $relObj ActiveRecord */
    $relObj = (empty($relPost[$relPKAttr[0]])) ? new $relModelClass() : $relModelClass::findOne($relPost[$relPKAttr[0]]);
    if (is_null($relObj)) {
    $relObj = new $relModelClass();
    }
    $relObj->load($relPost, '');
    $container[] = $relObj;
    }
    }
    $this->populateRelation($relName, $container);
    } else {

  2. in /var/www/html/re-exchange/vendor/mootensai/yii2-relation-trait/RelationTrait.php at line 135 – yii\base\ErrorHandler::handleError(8, 'Undefined offset: 0', '/var/www/html/re-exchange/vendor...', 135, ...)
    129130131132133134135136137138139140141 $this->populateRelation($relName, $container);
    } else if ($isHasMany) {
    $container = [];
    foreach ($v as $relPost) {
    if (array_filter($relPost)) {
    /* @var $relObj ActiveRecord */
    $relObj = (empty($relPost[$relPKAttr[0]])) ? new $relModelClass() : $relModelClass::findOne($relPost[$relPKAttr[0]]);
    if (is_null($relObj)) {
    $relObj = new $relModelClass();
    }
    $relObj->load($relPost, '');
    $container[] = $relObj;
    }

  3. in /var/www/html/re-exchange/vendor/mootensai/yii2-relation-trait/RelationTrait.php at line 83 – app\models\base\BasisTypeAssetCategory::loadToRelation(true, 'basisTypeAssetCategoryHasUses', [['tbl_basis_type_asset_use_id' => '2', 'share' => '', 'notice' => '']])
    77787980818283848586878889 $isHasMany = is_array($attr) && is_array(current($attr));
    $relName = ($isHasMany) ? lcfirst(Inflector::pluralize($model)) : lcfirst($model);
    if (in_array($relName, $skippedRelations) || !array_key_exists($relName, $relData)) {
    continue;
    }

                     $this->loadToRelation($isHasMany, $relName, $attr);
                 }
             }
         }
         return true;
     }
     return false;
    
  4. in /var/www/html/re-exchange/controllers/BasisTypeAssetCategoryController.php at line 93 – app\models\base\BasisTypeAssetCategory::loadAll(['_csrf' => 'GCjOoDVqRsT4p-joVRuKygmfz-hx-mx8...', 'BasisTypeAssetCategory' => ['id' => '5', 'tbl_basis_type_asset_id' => '2', 'name' => 'Shopping-Center', 'notice' => '', ...], 'BasisTypeAssetCategoryHasUse' => [['tbl_basis_type_asset_use_id' => '2', 'share' => '', 'notice' => '']], 'Children' => [['id' => '']]])
    87888990919293949596979899 if (Yii::$app->request->post('_asnew') == '1') {
    $model = new BasisTypeAssetCategory();
    }else{
    $model = $this->findModel($id);
    }

     if ($model->loadAll(Yii::$app->request->post()) && $model->saveAll()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('update', [
             'model' => $model,
         ]);
     }
    
  5. app\controllers\BasisTypeAssetCategoryController::actionUpdate('5')

  6. in /var/www/html/re-exchange/vendor/yiisoft/yii2/base/InlineAction.php at line 57 – call_user_func_array([app\controllers\BasisTypeAssetCategoryController, 'actionUpdate'], ['5'])

  7. in /var/www/html/re-exchange/vendor/yiisoft/yii2/base/Controller.php at line 157 – yii\base\InlineAction::runWithParams(['id' => '5'])

  8. in /var/www/html/re-exchange/vendor/yiisoft/yii2/base/Module.php at line 528 – yii\base\Controller::runAction('update', ['id' => '5'])

  9. in /var/www/html/re-exchange/vendor/yiisoft/yii2/web/Application.php at line 103 – yii\base\Module::runAction('basis-type-asset-category/update', ['id' => '5'])

  10. in /var/www/html/re-exchange/vendor/yiisoft/yii2/base/Application.php at line 386 – yii\web\Application::handleRequest(yii\web\Request)

  11. in /var/www/html/re-exchange/web/index.php at line 12 – yii\base\Application::run()
    6789101112
    require DIR . '/../vendor/autoload.php';
    require DIR . '/../vendor/yiisoft/yii2/Yii.php';

$config = require DIR . '/../config/web.php';

(new yii\web\Application($config))->run();

$_GET = [
'id' => '5',
];

$_POST = [
'_csrf' => 'GCjOoDVqRsT4p-joVRuKygmfz-hx-mx8cgX77MU2AJV-TIuUAwAp_MDSrZIjaei7RPWMm0ObITMoaMqCsVBaww==',
'BasisTypeAssetCategory' => [
'id' => '5',
'tbl_basis_type_asset_id' => '2',
'name' => 'Shopping-Center',
'notice' => '',
'order_by' => '',
],
'BasisTypeAssetCategoryHasUse' => [
[
'tbl_basis_type_asset_use_id' => '2',
'share' => '',
'notice' => '',
],
],
'Children' => [
[
'id' => '',
],
],
];

$_COOKIE = [
'77e87b2a364dc8c70b02561da86a5b95' => '17uqjbbjf9su22sucoqrei0tr2',
'PHPSESSID' => 'ah8f6pnntq9bq1j272hfn1lij7',
'_csrf' => 'd784c2e2798cd0fe8b700e895d008a22e9d05489a77aeffa9462961a0aafabada:2:{i:0;s:5:"_csrf";i:1;s:32:"fdE46jo88uEzvrbqMjCs2aMOZm1ntfZV";}',
];

$_SESSION = [
'__flash' => [],

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant