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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:31:27+00:00 2026-06-13T12:31:27+00:00

In a Cakephp v2.3 App, there are two models: Purchase Model : it contains

  • 0

In a Cakephp v2.3 App, there are two models:

Purchase Model: it contains the following main fields: id, invoice_date & gross_amount(calculated on Supplier.tax_rate).

class Purchase extends AppModel {

    public $displayField = 'id';
    public $belongsTo = 'Supplier';
}

Supplier Model: it contains id, name & tax_rate

class Supplier extends AppModel {
    public $displayField = 'name';
    public $hasMany = 'Purchase';
}

This is how my Add view of PurchasesController Looks:
enter image description here

Now, I want to get Supplier.tax_rate of currently selected supplier displayed In app/View/Purchase/add.ctp as label or text input.

Any idea how to do this?

  • 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-13T12:31:28+00:00Added an answer on June 13, 2026 at 12:31 pm

    I figured it out.
    What, I ended up doing was putting all supplier tax rate data as JSON, outputting that into the view & then using client-side javascript to select the relevant code.

    PurchasesController calls a custom model method which fires up a SQL query to get all supplier tax rate data.

    $supplier_tax_rate = $this->Purchase->Supplier->getTaxRate();
    $this->set('supplier_tax_rate', json_encode($supplier_tax_rate));
    

    The, in the client-side. I used Javascript to do what I wanted, here supplier_tax_rates is the variable which stored JSON tax rate data & getTaxRate is a variable function which returns tax rate from JSON based on id from supplier downdown.

    $(function() {
        var taxRates = $.parseJSON(supplier_tax_rates);
    
        var getTaxRate = function(id) {
            for (var i in taxRates) {
                if (taxRates[i].id == id) {
                    return taxRates[i].tax_percentage_charged;
                }
            }
        };
    }); 
    

    This has worked nicely for me, Hope it helps other people who want to get some data from database in cake, based on the value of dropdown.

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

Sidebar

Related Questions

I have an issue with using the following code in my CakePHP app. In
Please have a look at this validation array in my cakephp app for model
Greetings! I have CakePHP based app on shared hosting I wonder if there's a
In my cakephp app I have an Option model. In my option/index view I
I have a CakePHP 1.3 application connecting to Solr 3.3 search. There are two
I'm making a main app in CakePHP 1.3.10 that has a couple of plugins.
I've got a CAKEPHP app which has the following rewrite rules in the .htaccess
I have the following tables for my CakePHP app that allows friendships between users:
I'm using CakePHP for a small web app and on one form page there's
I have a simple cakephp app with table articles that has a cat_id column

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.