$_POST Problems

Now a week into php and Yii, I am running into some obstacles. I am trying to link to a new page depending on the selected dropdown item, passing the value to _POST, but for some reason, _POST is never set. I have my code listed below. Thanks for looking. Any help will be greatly appreciated.

controller code:

public function actionList()

    {


            if(isset($_POST['id']))


            {


                    $this->render($industry->name, array('/industry/show','id'=>$industry->id));


            }


            else


            {


                    $criteria=new CDbCriteria;





                    $pages=new CPagination(Contact::model()->approved()->count($criteria));


                    $pages->pageSize=self::PAGE_SIZE;


                    $pages->applyLimit($criteria);





                    $sort=new CSort('Contact');


                    $sort->attributes = array(


                            'user'=>array(


                                    'asc'=>'lname, fname',


                                    'desc'=>'lname DESC, fname DESC',


                                    'lable'=>'Contact'


                            ),


                            'graduation'=>'graduation',


                    );


                    $sort->applyOrder($criteria);





                    $models=Contact::model()->approved()->with('companies')->findAll($criteria);





                    $industries = array();


                    foreach(Industry::model()->findAll() as $industry)


                    {


                            $industries[$industry->id] = $industry->name;


                    }





                    $this->render('list',array('models'=>$models,'sort'=>$sort,'industries'=>$industries,'pages'=>$pages));


            }


    }

view code: (this isn’t all of the view code, but the relevant parts. if you think I need to supply something else, let me know!)

<div id="filter">

    Filter by Industry:





    &lt;?php echo CHtml::dropDownList('id','name', &#036;industries); ?&gt;





    &lt;?php echo CHtml::submitButton('Filter'); ?&gt;


    &lt;br /&gt;

</div>

<? if(!empty($testMessage))

{

    ?&gt;&lt;div id=&quot;test&quot;&gt; &lt;?php echo &#036;testMessage; ?&gt;&lt;/div&gt;&lt;?


    &#036;testMessage = &quot;&quot;;

} ?>

Thanks again!

I see the problem, according to what you have here:




<?php


$industries = array();

                        foreach(Industry::model()->findAll() as $industry)

                        {

                                $industries[$industry->id] = $industry->name;

                        }



You are using a foreach statement to find all the industries and store it into $industry. So $industry is simply a variable, it’s not a class thus $industry->id will not work.

Try this:




<?php


foreach(Industry::model()->findAll() as $industry)

{

     $industryID=$industry['id'];

     $industries[$industryID] = $industry['name'];

}



That should do the trick.

I’m assuming you want to make an array where the indexing values of the array are the ids of the industry and they hold the name of the industry as it’s value.

You should include the dropDownList in a form, in order to have the submit of his value:




<div id="filter">

        Filter by Industry:

<?php echo CHtml::Form();?>

        <?php echo CHtml::dropDownList('id','name', $industries); ?>


        <?php echo CHtml::submitButton('Filter'); ?>

        <br />


<?php echo CHtml::endForm();?>

</div>



You can also enjoy to use autoSubmit feature of dropDownList:




<div id="filter">

        Filter by Industry:

        <?php echo CHtml::dropDownList('id','name', $industries, array('submit'=>'')); ?>


        <br />

</div>



In this case is not needed even the submitButton.

Thanks a lot to both of you! It works great!