1

I have shop struct like

1: Shop has many Categories

2: Categories have 1 to many Sizes and Products

3: Each product belongs to exactly one Category

4: As Sizes belongs to Categories so each product belonging to a category will have same sizes.

Now my problem is in Product add form.

I have form the contains product's input fields and a selectbox to select the Category.

As soon as I select a category, an Ajax request will be created, which return sizes as inputbox assigned to the selected category. The input boxes will be used to enter the price for each size of the product. (As the input fields will be generated in Ajax, how may i use the form helper?)

Now I want that on clicking the save button, the product information should be stored in product table, and the prices should be saved in

Product_Prices table which contains product_id, size_id, price columns.

How should i name my inputboxs? and how should i call the save method so that the informations are properly saved?

1 Answer 1

2

To save one-size

//$this->Form->create('Product');
$this->Form->input('category_id');

To save many-size

//$this->Form->create('Shop');

$this->Form->input('category_id');

or use checkbox instead list

$this->Form->input('category_id', array('multiple' => 'checkbox')); 

If you want to save property of another model together with you main model you add model name (alias) as prefix and use saveAssociated() or saveAll().

echo $this->Form->input('ProductPrice.price');

see: http://book.cakephp.org/2.0/en/models/saving-your-data.html#model-saveall-array-data-null-array-options-array

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.