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 8812459
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:36:39+00:00 2026-06-14T03:36:39+00:00

I want to add data in two tables form one controller file when I

  • 0

I want to add data in two tables form one controller file when I call function for add data in second one table ..error comes Error: Call to a member function save() on a non-object

Here is my controller file

<?php
class CountryController extends AppController {
    var $name = 'Country';
    var $helpers = array('Html', 'Form' );


    // called index function 
    public function index() {
        $this->render();
    }

    // Function for add countries in database
    public function addCountry() {
        if (empty($this->data)) {
            $this->render();
        } else {
        //  $this->cleanUpFields();
            if ($this->Country->save($this->data)) {
                $this->Session->setFlash('The Counrty has been saved');
                $this->redirect('/country/index');
            } else {
                $this->Session->setFlash('Please correct errors below.');
            }
        }
    }

    public function addCity() {
        $cities = $this->set('country', $this->Country->find('all'));
        $this->set(compact('cities'));
        if(empty($this->data)){
            $this->render();
        } else {
            print_r($this->data);// die();
            if ($this->City->save($this->data)) {
                $this->Session->setFlash('The City has been saved');
                $this->redirect('/country/index');
            } else {
                $this->Session->setFlash('Please correct errors below.');
            }
        }
    }

}
?>
  • 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-14T03:36:40+00:00Added an answer on June 14, 2026 at 3:36 am

    var $uses = array(‘Main model name’ , ‘2nd model name’ …….so on);

    Eg:

    <?php
    class CountryController extends AppController {
        var $name = 'Country';
        var $helpers = array('Html', 'Form' );
        // $uses is where you specify which models this controller uses
        var $uses = array('Country', 'City');
    
        // ... here go your controller actions (methods)
    
    }
    ?>  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to join two tables together and have ONLY the data in Table
I have two tables (subjects and pages) in one-to-many relations. I want to add
I want to use Expression.Add to sum two data types, which might be a
I have two results from a data set. I want to add both results
I want to use echo to add data into a text file progressively. I
I want to add an XML file, containing sensitive data, to my application. I
Trying to add a view that combines data from two tables with a right
i want to add data to listview but my data are as String[] and
i want to add a data indicator line similar to the following image in
I want to add the data-val-required and data-val attributes to an @html.textbox or an

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.