I recently started using codeigniter. trying to create a new model for a new table. It seems save() method is not working properly. I am not able to see new records in my table.I did some research over net and stackoverflow, but no use. Can someone please check my code and advice.
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
2
3 class Listing_Price_History extends DataMapper
4 {
5
6 var $table = 'listing_price_history';
7 var $primary_key = 'id';
8 var $primary_key_suffix = '_uid';
9
10
11 // --------------------------------------------------------------------
12 /** Validations for the requried fields */
13 var $validation = array(
14 'listing_id' => array(
15 'label' => 'Listing Id',
16 'rules' => array('required')
17 ),
18 'price_per_sqft' => array(
19 'label' => 'Price per square feet',
20 'rules' => array('required')
21 )
22 );
23
24 // --------------------------------------------------------------------
25
26 public function __construct() {
27 parent::__construct();
28 $CI =& get_instance();
29 $CI->load->library('uuid');
30 $this->uuid = $CI->uuid;
31 $CI->load->helper('company');
32
33 }
34
35 // --------------------------------------------------------------------
36
37 // --------------------------------------------------------------------
38
39 /**
40 * Create listing entry
41 *
42 * @return bool
43 **/
44 public function savePriceHistory($history) {
45 // var_dump($history);
46 // var_dump($this);
47 if(isset($history['listing_id']))
48 $this->listing_id = $history['listing_id'];
49 if(isset($history['price_per_sqft']))
50 $this->price_per_sqft = $history['price_per_sqft'];
51 $date = date('Y-m-d H:i:s');
52 $this->created_by = $this->uuid;
53 $this->created_date = $date;
54 $save_history = $this->save();
55 // var_dump($this->check_last_query());
56 // var_dump($this->db->_error_message());
57 // var_dump($this->db->_error_number());
58 // var_dump($save_history);
59 }
60 }
60,1 Bot
Controller: This is how I am calling model
432 if($status){
433 echo "Entered";
434 $price_history = new Listing_Price_History();
435 $save_history = $price_history->savePriceHistory($history);
436 echo $save_history;
437 echo "Finished";
438 }
this is my table structure
please let me know where I am doing wrong.
</div>
I have this issue from time to time and have to remind myself that on some codeigniter systems datamapper creates files in the cache directory that it uses to keep database table meta-data. If you add a column to the database it won't automatically be accessible if a cache file exists.
So in codeigniter go to the app/cache directory and remove the file with the same name as your table. You should find that it is rebuilt the first time you use it with the new table schema and that it will all work