Monday, February 27, 2012

Re: Selecting products that are found in the selected category.

Where in your controller are you attempting to run any finds with conditions using the category or product id?

On Monday, 27 February 2012 08:56:08 UTC, Smooth wrote:
Hey everyone,

I have a page where you can add products to a list, on that page i
want a select for the categories and a select for the products, if the
categories select is changed i want the products select to list all
the products in that selected categorie.. I tried some of the info i
found on the internet but i wasnt able to fix this..

This is the code of the controller:

<?php
class OrderLinesController extends AppController {
    var $name = 'OrderLines';

    public function index() {

    }

    public function view() {
        $orderline = $this->OrderLine->find('all');
        $this-
>set(compact('orderline'));
        }

    public function add() {
        if ($this->request->is('post')) {
            if (!empty($this->data)) {
                //$this->OrderLine->create();
                //$this->OrderLine->save($this->data);
                echo $this->Session->setFlash(__('Orderline
succesfully registered'));
                //$this->redirect(array('controller' => 'orderlines',
'action' => 'view'));
            } else {
                echo $this->Session->setFlash(__('Please fill in all
fields'));
            }

        }

        $categories = $this->OrderLine->Product->Category-
>find('list');
        $this->set(compact('categories'));

        $products = $this->OrderLine->Product->find('list');
        $this->set(compact('products'));
    }
}
?>

The model:

<?php
class OrderLine extends AppModel
{
    var $name = 'OrderLine';
    var $belongsTo = 'PersonalOrder';
    var $hasOne = 'Product';
}
?>

And the view called add.ctp:

<?php
    echo $this->Form->create('OrderLine', array(
        'action' => 'add',
        'name' => 'cat_select'
    ));
    echo $this->Form->input('category_id', array(
        'type' => 'select',
        'style' => 'text-transform: capitalize',

    ));
    echo $this->Form->input('product_id', array(
        'type' => 'select'
    ));
    echo $this->Form->submit();
    echo $this->Form->end();
?>

Thanks.

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
 
 
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

No comments: