Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8409773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:00:15+00:00 2026-06-10T00:00:15+00:00

Controller: $data = array( ‘ContentI18n’ => array( 0 => array( ‘title’ => ‘first’, ‘author’

  • 0

Controller:

    $data =
            array(
                'ContentI18n' =>
                array(
                    0 =>
                    array(
                        'title' => 'first',
                        'author' => 'first',
                        'source' => 'sgfsdfrst',
                        'lang' => 'fa',
                    ),
                ),
                'Content' =>
                array(
                    'publish' => 1,
                    'type' => 3,
                    'pages' => 8,
                    'volume' => 7,
                    'modified' => '2012-05-27 14:16:37',
                    'created' => '2012-05-27 14:16:37',
                    'lang' => 'fa',
                ),
    );
$this->Content->create();
$this->Content->saveAll($data);

Model:

public $hasMany = array(
    'ContentI18n' => array(
        'className' => 'ContentI18n',
    )
);

beforeSave function in behavior:

public function beforeSave(Model $model) {
    // Define the new Translate model
    App::uses($model->name . 'I18n', 'Model');
    $varI18n = $model->name . 'I18n';
    $modelI18n = new $varI18n;


    foreach ($model->data[$model->name] as $key => $data) {
        if (!in_array($key, $this->setting))
            $modelData[$model->name][$key] = $data;
        else
            $modelData[$model->name . 'I18n'][0][$key] = $data;
    }
    $modelData[$model->name . 'I18n'][0]['lang'] = $model->locale;
    $modelData[$model->name]['lang'] = $model->locale;
    $model->data = $modelData;

    //pr($model->data);
    return TRUE;
}

every things seems be cause when is save it directly it’s save with saveAll. but when i use same structure of data in behavior did not work without any error.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T00:00:17+00:00Added an answer on June 10, 2026 at 12:00 am

    I found out that beforeSave callback will not trigger by saveAll. for executing some code before saveAll we must override saveAll function in our model.

    public function saveAll($data, $options = array()) {
                /*
                your code you want execute before saving...
                */
        parent::saveAll($data, $options);
    }
    

    for other saving methods such as saveMany,saveAssociated,… beforeSave trigger by them.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a View Controller where I select some data into an array and
I am using Codeigniter to pass an array of data from a controller into
I'm using Nsoutline view with core data and array controller , how can i
I am posting data to controller like this: var postVars = new Array(); postVars[0]
I want to access the value of a view controller data member variables in
hi guys i'm posting some data to controller using jquery ajax, but i am
Trying to post JSON data to Spring controller.. Not working at all JSP Code:
I'm passing data between my controller and my view using a ViewModel class. When
How can in controller redirect with post same data like this do form <form
In controller code, I have data in json format data = { 1: {assetId:1,status:true},

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.