最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

slug - CakePHP 5 - Slugging for CakePHP - Stack Overflow

programmeradmin0浏览0评论

In the application I am working on, I use the 'Slug' plugin - I can fetch records in the default language without any problems, but I am unable to do so in the translated languages. A simplified PHP code looks like this:

public function index($slug=null)
{
    $this->ServiceUnits = $this->fetchTable('ServiceUnits');
    $serviceUnit = $this->ServiceUnits->find('slugged', slug: $slug)->first();
}

CREATE TABLE IF NOT EXISTS `service_units` (
    `id` int NOT NULL AUTO_INCREMENT,
    `title` varchar(255) DEFAULT NULL,
    `text` text,
    `slug` varchar(100) DEFAULT NULL,
    `active` tinyint(1) NOT NULL DEFAULT '0',
    `position` float DEFAULT NULL,
    PRIMARY KEY (`id`)
);

CREATE TABLE IF NOT EXISTS `service_units_translations` (
    `id` int NOT NULL,
    `locale` varchar(5) NOT NULL,
    `title` varchar(255) DEFAULT NULL,
    `text` text,
    `slug` varchar(100) DEFAULT NULL,
    PRIMARY KEY (`id`,`locale`)
  );

How can I retrieve data from the service_units_translations table using the 'Slug' plugin?

In the application I am working on, I use the 'Slug' plugin - https://github/UseMuffin/Slug I can fetch records in the default language without any problems, but I am unable to do so in the translated languages. A simplified PHP code looks like this:

public function index($slug=null)
{
    $this->ServiceUnits = $this->fetchTable('ServiceUnits');
    $serviceUnit = $this->ServiceUnits->find('slugged', slug: $slug)->first();
}

CREATE TABLE IF NOT EXISTS `service_units` (
    `id` int NOT NULL AUTO_INCREMENT,
    `title` varchar(255) DEFAULT NULL,
    `text` text,
    `slug` varchar(100) DEFAULT NULL,
    `active` tinyint(1) NOT NULL DEFAULT '0',
    `position` float DEFAULT NULL,
    PRIMARY KEY (`id`)
);

CREATE TABLE IF NOT EXISTS `service_units_translations` (
    `id` int NOT NULL,
    `locale` varchar(5) NOT NULL,
    `title` varchar(255) DEFAULT NULL,
    `text` text,
    `slug` varchar(100) DEFAULT NULL,
    PRIMARY KEY (`id`,`locale`)
  );

How can I retrieve data from the service_units_translations table using the 'Slug' plugin?

Share Improve this question asked Nov 20, 2024 at 11:05 user3661042user3661042 1671 silver badge13 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

The problem was solved in this way: https://book.cakephp./5/en/orm/behaviors/translate.html#querying-translated-fields

发布评论

评论列表(0)

  1. 暂无评论