Yii Framework Forum: Unable to save data in database - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Unable to save data in database Unable to save data in database

#1 User is offline   callmesid 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 34
  • Joined: 26-November 16

Posted 14 December 2017 - 02:09 AM

Hello experts,

Can you please guide me how to save data in the database? below is the model, controller and view code for your reference.
Model:

class TestForm extends Model

 public static function tableName()
    {
        return '{{%test%}}';
    }
{
     
     public $value1;
     public $value2;
     public $value3;
     
 public function rules()

	{
	return[
        
        ['value1','required'], 
        ['value2','required'],
              ];
	}
 
  public function attributeLabels()
    {
        return [
            
            'value1' => '',
            'value2' => '',
            'value3' => 'Test output',
            
               ];
    }



Controller:


class TestController extends Controller

{
  
  public function actionTest(){
      
    $val1='A';
    $val2='B';
    $val3='C';

    return $this->render('index', ['Text1' => $val1, 'Text2' => $val2, 'Text3'=>$val3]);
    } 
}



View:
<div id= "content">
         <?php $form = ActiveForm::begin([
           'id' => 'form-testform'])?>
                    
<div class="row">
	<div class="col-xs-1">

	<?=$Text1 ?>

	</div>

	<div class="col-xs-1">

	<?=$Text2 ?>

	</div>
        <div class="col-xs-1">

	<?=$Text3 ?>

	</div>
			
	</div>
<div class="form-group"><?php ActiveForm::end(); ?> </div>



Thanks in advance.


Regards,
Sid
0

#2 User is offline   umneeq 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 170
  • Joined: 10-October 11
  • Location:Russia

Posted 14 December 2017 - 02:22 AM

Try render code with Gii. This will be a good hint.
0

#3 User is offline   callmesid 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 34
  • Joined: 26-November 16

Posted 14 December 2017 - 07:30 AM

Hello Experts,

Is there any way to relate "$value1, $value2, $value3" of Model with "$val1, $val2, $val3" of controller, so that when trigger submit button, the values will be saved in the db?

Regards,

Sid
0

#4 User is offline   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 3,498
  • Joined: 16-February 11
  • Location:Japan

Posted 14 December 2017 - 09:12 AM

You have to learn the basic concepts of the yii framework.

Read the following sections of the guide before you ask another question.

Getting Started

0

#5 User is offline   Stefano Mtangoo 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 363
  • Joined: 02-January 12
  • Location:Dar es Salaam, Tanzania

Posted 27 December 2017 - 09:04 AM

I agree with softark. You need to read the guide to get used to Yii. Model can use acrive record or data access objects
And God said, Let there be science...and it was so! Jukwaa la wanaoongea Kiswahili Hapa, and its github repo here
0

#6 User is offline   callmesid 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 34
  • Joined: 26-November 16

Posted 18 January 2018 - 01:04 AM

View PostStefano Mtangoo, on 27 December 2017 - 09:04 AM, said:

I agree with softark. You need to read the guide to get used to Yii. Model can use acrive record or data access objects


Hello team,

Thanks for your inputs.

I have understood the points. I have sorted out the issue.

Regards,

Sid
1

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users