69637

how to show new added columns in database in yii framework?

i added two new columns in my db table, and then i defined these new columns in the table model itself, and then, when i called

$model->getAttributes()

the two new columns didn't appear in the array output of $model->getAttributes() method call

there's no schema caching set in my configs, any idea how to solve this?, and how am I gonna get the value of the input forms of the new added columns from the front-end if i have a problem in showing off the two newly added columns ?

e.g

new columns INHOUSE OUTHOUSE

//view

<?php echo $form->checkBox($model,'INHOUSE',array("id"=>"inhouse","value"=>1, "uncheckValue"=>0));?> <?php echo $form->checkBox($model,'OUTHOUSE',array("id"=>"outhouse","value"=>1, "uncheckValue"=>0));?>

//controller update action

i tried to save the value of the INHOUSE and OUTHOUSE didn't get saved when i do

$model->attributes = $_POST['users']; $model->save();

NOR

$model->INHOUSE = $_POST['users']['INHOUSE']; $model->OUTHOUSE = $_POST['users']['OUTHOUSE']; $model->save;

any ideas how to solve all those problems?

Answer1:

1-Can you insert data directly into your DB on those columns? 2-Can you view those columns on the admin view or on any other view? 3-Can you retrieve those values using a getColumn method?

If not, try this:

Make sure that you have the new columns specified in your model and view

Model_Name.php

public function attributeLabels() { return array( 'id' => 'ID', // example 'new_column' => 'New Column', ... ); }

You should also check from TOP to bottom and as a good practice you should also type this on the top of the model

* @property integer $id //example * @property data_type $new_column ...

Then to view your new columns you need to add them to the necessary views.

example

VIEW.PHP

$this->widget('zii.widgets.CDetailView', array( 'data'=>$model, 'attributes'=>array( 'id', 'new_column', ...

If you have your model with all these definitions you should be able to retrieve those values from the DB, re-check any custom functions that you may have.

Answer2:

Please goto to : protected/runtime folder and delete all files. And try again.

Recommend

  • Save disconnected object in entity framework 4
  • JMock- java.lang.NoSuchMethodError: org.hamcrest.Matcher.describeMismatch()
  • UITableView Multiselect in MonoTouch
  • Subclassing a Pandas DataFrame, updates?
  • Modifying files nested in tar archive
  • css font-size and line-height not matching the baseline
  • C++ Pointer Arrays
  • How to name a 'group' check box in Adobe Reader when wanting to fill form by FDF / XFDF
  • Certain Arabic text gets incorrectly shown while other Arabic text gets showed normally?
  • How to implement Deep Linking in Roku SG application?
  • Add reference to ASP.NET 5 Class Library from Framework 4.5 Class Library Project
  • Updating both a ConcurrentHashMap and an AtomicInteger safely
  • Angularjs pass function from Controller to Directive (or call controller function from directive) -
  • How does this usort cmp function actually work?
  • Stop Bash Script if Hive Fails
  • How to add git credentials to the build so it would be able to be used within a shell code?
  • ActiveRecord query for a count of new users by day
  • Lost migrations and Azure database is now out of sync
  • Javascript Callbacks with Object constructor
  • Join two tables and save into third-sql
  • How to model a transition system with SPIN
  • Display Images one by one with next and previous functionality
  • Upload files with Ajax and Jquery
  • ORA-29908: missing primary invocation for ancillary operator
  • jQuery tmpl and DataLink beta
  • Do I've to free mysql result after storing it?
  • Cannot Parse HTML Data Using Android / JSOUP
  • A cron job substitute?
  • json Serialization in asp
  • SQL merge duplicate rows and join values that are different
  • Proper way to use connect-multiparty with express.js?
  • How to set the response of a form post action to a iframe source?
  • How get height of the a view with gone visibility and height defined as wrap_content in xml?
  • Getting Messege Twice Using IMvxMessenger
  • costura.fody for a dll that references another dll
  • Observable and ngFor in Angular 2
  • UserPrincipal.Current returns apppool on IIS
  • Converting MP3 duration time
  • java string with new operator and a literal
  • How to load view controller without button in storyboard?