请教thinkphp中Model的一个小问题
小白
小白 2017-02-24 09:18:23
0
2
2133

各位大神好!我看到一个thinkphp教程里面在Application->Common->Model文件夹中创建了一个BasicModel.class.php文件,但是教程中的数据库中并没有Basic表,可是为什么可以正常使用这个模型呢?(我也模仿写了一个,但是提示Table 'test.base' doesn't exist)

<?phpnamespace 
Common\Model;use 
Think\Model;class BasicModel extends Model {    
    public function __construct() {

    }    
    public function save($data = array()) {
            if(!$data) {
            throw_exception('没有提交的数据');
        }        
        $id = F('basic_web_config', $data);        
        return $id;
       }    
       public function select() {
         return F("basic_web_config");
        }
}

logo.jpg1.png

小白
小白

好好学习,天天向上!!!

répondre à tous(2)
数据分析师

Posez-moi une petite question sur le modèle dans thinkphp - Questions et réponses sur le site Web PHP chinois - Posez-moi une petite question sur le modèle dans thinkphp - Questions et réponses sur le site Web PHP chinois

Jetez un œil autour de vous et apprenez.

迷茫

模型类的作用大多数情况是操作数据表的,如果按照系统的规范来命名模型类的话,大多数情况下是可以自动对应数据表。 
模型类的命名规则是除去表前缀的数据表名称,采用驼峰法命名,并且首字母大写,然后加上模型层的名称(默认定义是Model),例如
模型名 约定对应数据表(假设数据库的前缀定义是 think_) 
UserModel think_user 
如果你的规则和上面的系统约定不符合,那么需要设置Model类的数据表名称属性,以确保能够找到对应的数据表。
例如,在数据库里面有一个 think_categories 表,而我们定义的模型类名称是 CategoryModel ,按照系统的约定,这个模型的名称是Category,对应的数据表名称应该是 think_category (全部小写),但是现在的数据表名称是 think_categories ,因此我们就需要设置 tableName 属性来改变默认的规则,等等

  • répondre &lt;strong&gt;J'aime&lt;/strong&gt;
    ringa_lee auteur 2017-10-12 15:29:29
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!