1

我正在按照本教程进行自动完成,它工作正常,除了 MY_X 的自动完成不起作用。

http://taggedzi.com/articles/display/autocomplete-eclipse-codeigniter-2

如何在 MY_X 类中启用自动完成功能?

MY_model 的代码例如:

class MY_Model extends CI_Model {

 public $auto_validate = TRUE; // use auto-validation before saving
 public $return_method = 'auto'; // object, array, query, auto
 public $auto_validate_fields = array(
  'email|email_address' => 'valid_email',
  'phone|phone_number' => 'valid_phone'
  ); // fields to auto validate
 public $required = array(); // required fields
 public $default_required_message;
 //public $default_required_message = "Please fill out the required field '%1s'"; // the default required validator message
 public $auto_date_add = array('date_added', 'entry_date'); // field names to automatically set the date when the value is NULL
 public $auto_date_update = array('last_modified', 'last_updated'); // field names to automatically set the date on updates
 public $date_use_gmt = FALSE; // datetime method
 public $default_date = 0; // default date value that get's passed to the model on save. Using 0000-00-00 will not work if it is a required field since it is not seen as an empty value
 public $auto_trim = TRUE; // will trim on clean
 public $auto_encode_entities = TRUE; // automatically encode html entities 
 public $xss_clean = FALSE; // automatically run the xss_clean
 public $readonly = FALSE; // sets the model to readonly mode where you can't save or delete data'
 public $hidden_fields = array(); // fields to hide when creating a form
 public $unique_fields = array(); // fields that are not IDs but are unique
 public $linked_fields = array(); // fields that are are linked. Key is the field, value is a function name to transform it
 public $foreign_keys = array(); // map foreign keys to table models

 protected $db; // CI database object
 protected $table_name; // the table name to associate the model with
 protected $key_field = 'id'; // usually the tables primary key(s)... can be an array if compound key
 protected $normalized_save_data = NULL; // the saved data before it is cleaned
 protected $cleaned_data = NULL; // data after it is cleaned
 protected $dsn = ''; // the DSN string to connect to the database... if blank it will pull in from database config file
 protected $has_auto_increment = TRUE; // does the table have auto_increment?
 protected $suffix = '_model'; // the suffix used for the data record class
 protected $record_class = ''; // the name of the record class (if it can't be determined)
 protected $rules = array(); // validation rules
 protected $fields = array(); // fields in the table
 protected $use_common_query = TRUE; // include the _common_query method for each query
 protected $validator = NULL; // the validator object

 /**
  * Constructor - Sets MY_Model preferences
  *
  * The constructor can be passed an array of config values
  */
 public function __construct($table = NULL, $params = array())
 { 
  parent::__construct(); 
  $this->default_required_message = lang('error_required_message').' \'%1s\''; // the default required validator message

  // load helpers here 
  $this->load->helper('string');
  $this->load->helper('date');
  $this->load->helper('security');
  $this->load->helper('language');

  $this->initialize($table, $params);
    }

 // --------------------------------------------------------------------

 /**
  * Initialize the user preferences
  *
  * Accepts an associative array as input, containing display preferences
  *
  * @access public
  * @param string the table name
  * @param array config preferences
  * @return void
  */ 
 public function initialize($table = NULL, $params = array())
 {
  if (!empty($table))
  {
   $this->table_name = $table;
  } 
  else 
  {
         $this->table_name = strtolower(get_class($this));
  }

  if (!empty($params))
  {
   foreach ($params as $key => $val)
   {
    if (isset($this->$key))
    {
     $this->$key = $val;
    }
   }
  }

  // if a DSN property is set,then we will load that database in
  if (!empty($this->dsn))
  {
   $this->db = $this->load->database($this->dsn, TRUE, TRUE);
  }
  else
  {
   // else we use the database set on the CI object
   if (empty($this->db))
   {
    $this->load->database($this->dsn);
   }
   $CI =& get_instance();
   if (isset($CI->db))
   {
    // create a copy of the DB object to prevent cross model interference
    unset($this->db);
    $this->db = clone $CI->db;
   }
   else
   {
    $CI->load->language('db');
    show_error(lang('db_unable_to_connect'));
   }
  }
  $this->validator = new Validator();
  $this->validator->register_to_global_errors = FALSE;

 }

 // --------------------------------------------------------------------

 /**
  * Returns the database object
  *
  * @access public
  * @return array
  */ 
 public function &db;()
 {
//   $this->_check_readonly();
  return $this->db;
 }

 // --------------------------------------------------------------------

 /**
  * Gets the short name minus the suffix
  *
  * @access public
  * @return array
  */ 
 public function short_name($lower = FALSE, $record_class = FALSE)
 {
  $class_name = ($record_class) ? $this->record_class_name() : get_class($this);
  $end_index = strlen($class_name) - strlen($this->suffix);
  $short_name = substr($class_name, 0, $end_index);
  if ($lower)
  {
   return strtolower($short_name);
  }
  else
  {
   return $short_name;
  }
 }

 // --------------------------------------------------------------------

 /**
  * Get the table name
  *
  * @access public
  * @return array
  */ 
 public function table_name()
 {
  return $this->table_name;
 }

.....  
4

1 回答 1

0

尝试这个:

  1. 右键单击 PHP Explorer 中的顶级文件夹。
  2. 选择“配置”菜单项,然后选择“添加 PHP 支持”

Eclpise 中的 PDT 自动完成功能中断

试试这个:Getting full auto complete with CodeIgniter in Eclipse

于 2012-08-06T20:20:56.730 回答