Updating problem

my controller:


 public function actionProfile()

        {

            $blogger_id     =   3;

            $model          =    Blogger::model()->find(array('condition'=>"id='$blogger_id'"));

            $model1         =    Note::model()->findAll();

            foreach ($model1 as $model1)

            {

                $data[]=array(

                    'note' => $model1->note,

                    'date' => $model1->date,

                    'time' => $model1->time,

                );

            }       

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

                {

                    $model->attributes=$_POST['blogger'];

                    die($aboutme);

                    $update     = Blogger::model()->updateByPk($blogger_id, array(

                                            'aboutme' =>$model->attributes,

                                                )); 

                }

            $this->render('profile',array('model'=>$model,'data'=>$data));

        }

my view:


<?php

/*This page view blogger information

 */

$this->breadcrumbs=array(

	'View Blogger',

);

?>

<div class="divblogger">

    <div class="divbloggerleft">

        <div class="divimg">

            <?php echo CHtml::image($model->image); ?>

        </div>    

    </div>

    <div class="divbloggerright">

        <table>

            <tr>

                <td class="tdspace">

                    <?php echo CHtml::encode($model->getAttributeLabel('blogger_name')); ?>:

                </td>

                <td>

                    <?php echo CHtml::encode($model->blogger_name); ?>

                </td>

            </tr>

            <tr>

                <td>

                    <?php echo CHtml::encode($model->getAttributeLabel('blog_name')); ?>:

                </td>

                <td>

                    <?php echo CHtml::encode($model->blog_name); ?>

                </td>

            </tr>

             <tr>

                <td>

                    <?php echo CHtml::encode($model->getAttributeLabel('blog_url')); ?>:

                </td>

                <td>

                    <?php echo CHtml::link($model->blog_url); ?>

                </td>

            </tr>

            <tr>

                <td>

                    <?php echo CHtml::encode($model->getAttributeLabel('email')); ?>:

                </td>

                <td>

                    <?php echo CHtml::link($model->email); ?>

                </td>

            </tr>

            <tr>

                <td>

                    <?php echo CHtml::encode($model->getAttributeLabel('contract_status')); ?>:

                </td>

                <td>

                    <?php echo CHtml::encode($model->contract_status); ?>

                </td>

            </tr>

            <tr>

                <td>

                    <?php echo CHtml::encode($model->getAttributeLabel('rating')); ?>:

                </td>

                <td>

                    <?php

                    $this->widget('CStarRating',array(

                                'name'=>'rating',

                                'value'=>CHtml::encode($model->rating),

                                'minRating'=>1,

                                'maxRating'=>5,

                                'readOnly'=>true,

                                ));

                    ?>

                </td>

            </tr>

        </table>

    </div> 

    <div class="divmain">

        <div class="noteheading">

            <span class="headingtext">Blogger Note</span>

        </div>

        <div class="divinner">

            <?php foreach ($data as $row): ?>

            <div class="divnote">

                <?php echo $row['note']; ?><br>

            </div>     

            <div class="divdate">

                <?php echo $row['date']; ?>

                <?php echo $row['time']; ?><hr>

            </div>

            <?php endforeach; ?>

        </div>

    </div>

</div>

<div class="divaccordian">

    <div class='inneracoordian'>

        <?php

        $this->widget('zii.widgets.jui.CJuiAccordion',array(

            'panels'=>array(

                'General/Personal Information'=>$this->renderPartial('_details',array('model'=>$model),true),

                'Project'=>$this->renderPartial('_project',null,true),

                'Surveys'=>$this->renderPartial('_surveys',null,true),

                'Social Media'=>$this->renderPartial('_social',null,true),

                'Add Notes'=>$this->renderPartial('_addnotes',null,true),

            ),

            // additional javascript options for the accordion plugin

            'options'=>array(

                'collapsible'=> true,

                'autoHeight'=>false,

                'active'=>0,

            ),

        ));

    ?>

    </div>

</div>



and




<div class="divabout">

    <div class="divabouthead">

        <span class="headingtext">About Me</span>

    </div>

    <?php echo CHtml::textArea('textbox',$value=$model->about_me); ?>

    <span class="abtbtn"><?php 

                    $this->widget('bootstrap.widgets.TbButton', 

                            array('buttonType' => 'submit', 

                                        'type' => 'primary', 

                                        'label' => 'Update')); 

                ?>   </span>

</div>

i am trying to update the textarea but it is not updating

Hello!

I think you must update also the data variable you are sending to the view:




public function actionProfile()

        {

            $blogger_id     =   3;

            $model          =    Blogger::model()->find(array('condition'=>"id='$blogger_id'"));

            $model1         =    Note::model()->findAll();

            foreach ($model1 as $model1)

            {

                $data[]=array(

                    'note' => $model1->note,

                    'date' => $model1->date,

                    'time' => $model1->time,

                );

            }       

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

                {

                    $model->attributes=$_POST['blogger'];

                    //die($aboutme);    //don't forget comment this

                    $update     = Blogger::model()->updateByPk($blogger_id, array(

                                            'aboutme' =>$model->attributes,

                                                )); 

                }

            //You have to update your $model variable, you have updated it in your database but not in the data you are

            //going to pass to the view


            $model = Blogger::model()->find(array('condition'=>"id='$blogger_id'"));

            $this->render('profile',array('model'=>$model,'data'=>$data));

        }

Actually i check it is not working .is use die it is also not working

if(isset()) is not working .

If the isset($_POST[‘blogger’]) doesn’t work the problem is you are not sending post data to the action.

Else, Have you checked if in the database the row has been updated? If not try this in your $model declaration:




$model = Blogger::model()->find("id= ".$blogger_id);



If doesn’t work you can also try:




$model = Blogger::model()->findByPk($blogger_id);



You have to debug your code and locate where is the problem source, it may be:

  • No data recieved, make: print_r(isset($_POST[‘blogger’])); at the beggining of the action.

  • The $model variable is not filled

  • The $model variable is filled correctly but the update doesn’t work

  • The update works but the view doesn’t show the changes

I have made some change so your action should be like this:




public function actionProfile()

	{

		$blogger_id     =   3;

		$model = Blogger::model()->find("id= ".$blogger_id);

		$model1         =    Note::model()->findAll();

		//Here i also changed the name of iterated item for a cleaner understanding

		foreach ($model1 as $m)

		{

			$data[]=array(

				'note' => $m->note,

				'date' => $m->date,

				'time' => $m->time,

			);

		}       

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

			{

				//you can see what fields are incoming by doing:

				//print_r($_POST['blogger']);

				$model->attributes=$_POST['blogger'];

				//die($aboutme);    //don't forget comment this

				$update = Blogger::model()->updateByPk($blogger_id, array(

										'aboutme' =>$model->attributes,

											)); 

			}

		//You have to update your $model variable, you have updated it in your database but not in the data you are

		//going to pass to the view

		$model = Blogger::model()->find("id= ".$blogger_id);

		$this->render('profile',array('model'=>$model,'data'=>$data));

	}



Try and comment please