简体   繁体   中英

Zend_Tool, create db-table.from-database doesn't work in project (module not found)

I have a Zend Framework project with an existing database, so I'd like to create models based on the tables that I have in my database. I can run zf commands from the command-line and in Netbeans just fine, for example generating controllers/forms works just fine. However, when I want to create the model from the database using the command

zf create db-table.from-database application force-overwrite

it gives me this error:

A models directory was not found for module application.               

Zend Framework Command Line Console Tool v1.12.1
Details for action "Create" and provider "DbTable"
  DbTable
    zf create db-table name actual-table-name module force-overwrite
    zf create db-table.from-database module force-overwrite

The same thing happens when I try it with

zf create db-table.from-database Application force-overwrite

Just to clarify: the models directory DOES exist in my project folder. I'm assuming I have to enter application because it's the module I'm working in (the default one).

My database connection is fine too, since I can execute queries just fine. Has anyone got an idea on how to fix this?

I've not used this feature, but 'application' is not a module. If you don't want it to scan a specific module folder I would guess you leave that parameter out. What happens if you just call zf create db-table.from-database force-overwrite ?

As with most things the problem can be as simple as a case sensitive and/or miss spelled directory name/path. I don't believe this problem can be solved without interaction/emulation.

I've never seen zf create db-table.from-database work in any circumstances. However if you want to try the netbeans command that should work is -m default ('default' is the module, add -f for force overwrite) the resulting command will look like: zf create db-table.from-database -m default .

Personally I just use the zf create db-table command to create just the db-table models I need.

This command would work zf create db-table users users -m admin -f where -m admin (the -m does seem to be required) is the module and -f indicates force over write. The first users is the name of the class (Application_Model_DbTable_Users, Users.php), the second users is the actual name of the database table.

I don't know what you're expecting as far a model goes, what you're going to get is something very similar to:

<?php

class Application_Model_DbTable_User extends Zend_Db_Table_Abstract
{
    protected $_name    = 'users';
}

This a very important class when using the Zend_Db component but if you're new to ZF it may be a little confusing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM