我有两个bundle主AppBundle和PrestaShopConnectionBundle从PrestaShop数据库获取信息。当我试图从ProductShop实体获取信息时,我得到了错误:
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'prestashop.ps_product_shop' doesn't exist
命令
php app/console doctrine:schema:update --dump-sql --em=prestashop
返回"Nothing to update",所以它可能是从PrestaShop检测到的表。但是为什么控制器不能从中获取日期呢?
<?php
//src/PrestaShopConnectionBundle/Entity/ProductShop.php
namespace PrestaShopConnectionBundle'Entity;
use Doctrine'ORM'Mapping as ORM;
/**
* @ORM'Entity
* @ORM'Table(name="prestashop.ps_product_shop")
*/
class ProductShop
{
/**
* @ORM'Column(type="integer")
* @ORM'Id
* @ORM'GeneratedValue(strategy="AUTO")
* @ORM'Column(name="id_product")
*/
protected $id;
/**
* @ORM'Column(type="decimal", precision=20, scale=6, name="price")
* @ORM'Column()
*/
protected $price;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set price
*
* @param string $price
* @return ProductShop
*/
public function setPrice($price)
{
$this->price = $price;
return $this;
}
/**
* Get price
*
* @return string
*/
public function getPrice()
{
return $this->price;
}
}
<?php
//src/PrestaShopConnectionBundle/Entity/ProductShop.php
namespace AppBundle'Controller;
use Sensio'Bundle'FrameworkExtraBundle'Configuration'Route;
use Symfony'Bundle'FrameworkBundle'Controller'Controller;
use PrestaShopConnectionBundle'Entity'ProductShop;
class DefaultController extends Controller
{
/**
* @Route("/app/example", name="homepage")
*/
public function indexAction()
{
$product = $this->get('doctrine')
->getRepository('PrestaShopConnectionBundle:ProductShop', 'prestashop')
->findAll();
dump($product);
return $this->render('default/index.html.twig');
}
}
config.yml
imports:
- { resource: parameters.yml }
- { resource: security.yml }
- { resource: services.yml }
# Put parameters here that don't need to change on each machine where the app is deployed
# http://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
parameters:
locale: en
framework:
#esi: ~
#translator: { fallbacks: ["%locale%"] }
secret: "%secret%"
router:
resource: "%kernel.root_dir%/config/routing.yml"
strict_requirements: ~
form: ~
csrf_protection: ~
validation: { enable_annotations: true }
#serializer: { enable_annotations: true }
templating:
engines: ['twig']
#assets_version: SomeVersionScheme
default_locale: "%locale%"
trusted_hosts: ~
trusted_proxies: ~
session:
# handler_id set to null will use default session handler from php.ini
handler_id: ~
fragments: ~
http_method_override: true
# Twig Configuration
twig:
debug: "%kernel.debug%"
strict_variables: "%kernel.debug%"
# Assetic Configuration
assetic:
debug: "%kernel.debug%"
use_controller: false
bundles: [ ]
#java: /usr/bin/java
filters:
cssrewrite: ~
#closure:
# jar: "%kernel.root_dir%/Resources/java/compiler.jar"
#yui_css:
# jar: "%kernel.root_dir%/Resources/java/yuicompressor-2.4.7.jar"
less:
node: /usr/bin/node
node_paths: [/usr/lib/node_modules]
# Doctrine Configuration
doctrine:
dbal:
default_connection: default
connections:
default:
driver: pdo_mysql
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
prestashop:
driver: pdo_mysql
host: "%database_shop_host%"
port: "%database_shop_port%"
dbname: "%database_shop_name%"
user: "%database_shop_user%"
password: "%database_shop_password%"
charset: UTF8
mapping_types:
enum: string
orm:
default_entity_manager: default
auto_generate_proxy_classes: "%kernel.debug%"
entity_managers:
default:
connection: default
naming_strategy: doctrine.orm.naming_strategy.underscore
mappings:
AppBundle: ~
PrestaShopConnectionBundle: ~
prestashop:
connection: prestashop
naming_strategy: doctrine.orm.naming_strategy.underscore
mappings:
PrestaShopConnectionBundle: ~
# Swiftmailer Configuration
swiftmailer:
transport: "%mailer_transport%"
host: "%mailer_host%"
username: "%mailer_user%"
password: "%mailer_password%"
spool: { type: memory }
mopa_bootstrap:
form:
show_legend: false # default is true
show_child_legend: false # default is true
error_type: block # or inline which is default
正如@OIS所指出的,@ORM'Table(name="prestashop.ps_product_shop")
是坏的!
我只是从我的应用程序中复制的,所以如果你能把它应用到你的应用程序中,它应该会很好。
parameters.yml
parameters:
database_driver: pdo_mysql
database_host: 127.0.0.1
database_port: ~
database_name: abc_dev
database_user: dev
database_password: mysqlpassword
database_path: ~
def_database_driver: pdo_mysql
def_database_host: 127.0.0.1
def_database_port: ~
def_database_name: def_dev
def_database_user: dev
def_database_password: mysqlpassword
def_database_path: ~
config.yml
doctrine:
dbal:
default_connection: abc
connections:
abc:
driver: %database_driver%
host: %database_host%
port: %database_port%
dbname: %database_name%
user: %database_user%
password: %database_password%
charset: UTF8
mapping_types:
enum: string
def:
driver: %def_database_driver%
host: %def_database_host%
port: %def_database_port%
dbname: %def_database_name%
user: %def_database_user%
password: %def_database_password%
charset: UTF8
mapping_types:
enum: string
orm:
auto_generate_proxy_classes: %kernel.debug%
default_entity_manager: abc
entity_managers:
abc:
connection: abc
mappings:
ApplicationAbcBundle:
dir: Entity/Abc
def:
connection: def
mappings:
ApplicationDefBundle:
dir: Entity/Def
<<p> 应用程序结构/strong> src
Application
AbcBundle
Entity
Abc
your entities....
DefBundle
Entity
Def
your entities....
命令行示例
app/console doctrine:schema:update --em:abc --force
app/console doctrine:generate:entities ...... --em:def