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

  • SEARCH
  • Home
  • 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 7167147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:31:51+00:00 2026-05-28T14:31:51+00:00

I have two database, 1st one is for Group and the 2nd one is

  • 0

I have two database, 1st one is for Group and the 2nd one is for Member. Now I want to validate the both models in a single form and the my group controller file is like this

public function actionCreate()
  {
    $model=new Group;
    $member=new Member;

    // Uncomment the following line if AJAX validation is needed
    // $this->performAjaxValidation($model);

    if(isset($_POST['Group'],$_POST['Member']))
    {
      $model->attributes=$_POST['Group'];
      //$member->attributes=$_POST['Member'];
      if($model->save())
      {
        $member->attributes=$_POST['Member'];
        $member->group_id = $model->id;
        if($member->save())
        {
          $this->redirect(array('view','id'=>$model->id));
        }
      }
        $this->redirect(array('view','id'=>$model->id));
    }

    $this->render('create',array(
      'model'=>$model,
      'member'=>$member,
    ));
  }

So how to make validate both models here.

  • 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-05-28T14:31:51+00:00Added an answer on May 28, 2026 at 2:31 pm

    You can create a class that extends CFormModel. This keeps your controller code simple and clean. Make sure it can be created with the default constructor. Then you pass in the data for the group and user, validate it, and then save it, like this:

    public function actionCreate() {
        $form = new CreateGroupForm();
    
        if (isset($_POST['Group'],$_POST['Member'])) {
            $form->setData($_POST['Group'], $_POST['Member']);
            if ($form->validate()) {
                $form->save();
            }
        }
        ...
    }
    

    The form class itself would create the group and member objects when you call setData(), and it simply validates both classes in validate(). Its save() method would look like you’ve done above.

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

Sidebar

Related Questions

I have two tables in my database, 1st one contains a couple of sentences,
I have two databases. I want to dump data from one table in 1st
I have two database tables, one in MYSQL and one in MSSQL. Both have
I have two database one with relationship(no data) and another with out Relationship (with
No real way for me to succinctly summarize this one. I have two database
i have two database one database in webserver and other database in local here
I have two MySQL database tables: one containing a list of championships and another
I have two database tables with a one-to-many relationship. Is it possible to select
Well, I have two tables in an sql database. One has an ID column
I have two different sites in my Intranet.. 1st site Database is MYSQL, &

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.