插入标签不存在的标签ID

时间:2018-07-04 08:30:43

标签: php mysql tags

我正在尝试向一本书插入多个或单个标签,我从此Should I store tags in a text field or in a separate table?中获得3个表格,例如books(书籍记录),tags(标签记录),books_tag(books和标签的关系)问题我有这个主意。

我首先将书籍和标签一起插入,然后获取书籍的最后添加的ID,然后尝试将标签和ID一起插入books_tag表中。我的代码非常适合为书添加新标签(标签表中不存在),但是如果我尝试插入已存在标签,则它总是在books_tag上插入标签ID为0(应该是标签表中的已存在标签ID)表,这是我的代码

// Load the autoloader class so that the controller can find everything it needs
//$loader = require 'app/vendor/autoload.php';
require 'app/vendor/autoload.php';

// Create a new Symfony kernel instance
$kernel = new \AppKernel('prod', false);
//$kernel = new \AppKernel('dev', true);
// Boot the kernel
$kernel->boot();
// Get the kernel container
$container = $kernel->getContainer();
// Services can be retrieved like so if you need to
//$service = $container->get('name.of.registered.service');

// Create a new instance of your controller
$controller = new \What\You\Call\Your\Bundle\Controller\FooBarController();
// You MUST set the container for it to work properly
$controller->setContainer($container);

0 个答案:

没有答案