Phalcon默认居然不能设置数据表前缀,常用的框架都支持。
修改方法一:
新建一个基础模型,然后所有的模型在该类上继承即可
	  
		|  代码如下 | 
		复制代码 | 
	  
	  
		| 
 
class BaseModel extends PhalconMvcModel { 
    public function getSource() 
    { 
        return 'gw_'.strtolower(get_class($this)); 
    } 
} 
 | 
但是此种方法,用phalcon devtools命令行模式生成model文件,文件名称是有表前缀的
修改方法二:
2.1 先在app/config/config.php 配置文件加上数据库前缀配置tablePrefix
	  
		|  代码如下 | 
		复制代码 | 
	  
	  
		| 
 'database' => array( 
        'adapter'     => 'Mysql', 
        'host'        => 'localhost', 
        'username'    => 'root', 
        'password'    => '', 
        'dbname'      => 'test', 
        'charset'     => 'utf8', 
        'port' => '3306', 
        'tablePrefix' => 'gw_' 
    ), 
 | 
2.2 修改phalcon devtools
代码phalcondevtoolsscriptsPhalconBuilderModel.php
在220行$table = $this->options->get(‘name’);之后加上代码
	  
		|  代码如下 | 
		复制代码 | 
	  
	  
		| 
  
$table = $this->options->get('name'); 
if(isset($config->database->tablePrefix)){ 
    $table = $config->database->tablePrefix.$table; 
} 
 | 
在480行
	  
		|  代码如下 | 
		复制代码 | 
	  
	  
		| 
 $methodRawCode[] = $this->snippet->getModelSource($this->options->get(‘name’)); 
修改代码为: 
$methodRawCode[] = $this->snippet->getModelSource($table); 
 | 
此时使用工具命令
phalcon model user
生成model :
app/models/User.php
内容如下,不会提示table不存在了:
PHP
	  
		|  代码如下 | 
		复制代码 | 
	  
	  
		| 
 
  
use PhalconMvcModelValidatorEmail as Email; 
  
class User extends PhalconMvcModel 
{ 
  
    /** 
     * 
     * @var integer 
     */ 
    public $id; 
  
    /** 
     * 
     * @var string 
     */ 
    public $username; 
  
    /** 
     * 
     * @var string 
     */ 
    public $password; 
  
    /** 
     * 
     * @var integer 
     */ 
    public $status; 
  
    /** 
     * 
     * @var string 
     */ 
    public $real_name; 
  
    /** 
     * 
     * @var string 
     */ 
    public $mobile; 
  
    /** 
     * 
     * @var string 
     */ 
    public $email; 
  
    /** 
     * 
     * @var integer 
     */ 
    public $sex; 
  
    /** 
     * 
     * @var integer 
     */ 
    public $logins; 
  
    /** 
     * 
     * @var integer 
     */ 
    public $create_time; 
  
    /** 
     * Validations and business logic 
     * 
     * @return boolean 
     */ 
    public function validation() 
    { 
        $this->validate( 
            new Email( 
                array( 
                    'field'    => 'email', 
                    'required' => true, 
                ) 
            ) 
        ); 
  
        if ($this->validationHasFailed() == true) { 
            return false; 
        } 
  
        return true; 
    } 
  
    /** 
     * Initialize method for model. 
     */ 
    public function initialize() 
    { 
        $this->setSource("gw_user"); 
    } 
  
    /** 
     * Returns table name mapped in the model. 
     * 
     * @return string 
     */ 
    public function getSource() 
    { 
        return 'gw_user'; 
    } 
  
    /** 
     * Allows to query a set of records that match the specified conditions 
     * 
     * @param mixed $parameters 
     * @return User[] 
     */ 
    public static function find($parameters = null) 
    { 
        return parent::find($parameters); 
    } 
  
    /** 
     * Allows to query the first record that match the specified conditions 
     * 
     * @param mixed $parameters 
     * @return User 
     */ 
    public static function findFirst($parameters = null) 
    { 
        return parent::findFirst($parameters); 
    } 
  
} 
 |