在MODX革命2.7.3中,我使用xpdo在modx安装的同一个数据库中插入和添加来自自定义表的数据。除了在xpod查询中显示表中的更改需要大约20分钟之外,一切都很好。
例如,我有一张与成人领域有联系的表格。在表单中,我有一个下拉框,其中的选项是成人联系人。它可以正常工作,但是当您更改联系人的成人状态时,下拉列表中的选项需要20分钟才能反映更改。
见下面的代码
$class='Contacts';
$fields = array_keys($modx->getFields($class));
$collections = $modx->getCollection($class);
foreach($collections as $collection) {
if($collection->get($fields[4])=='YES'){
$output .= '<option value=' . $collection->get($fields[0]).'>'.$collection->get($fields[1])." ".$collection->get($fields[2]).'</option>';
}
}
return $output;
There is only one table involved and the code for creating the table is:
CREATE TABLE `cbdb_contacts` (
`contactID` int(11) NOT NULL,
`firstname` varchar(15) COLLATE utf8_unicode_ci NOT NULL,
`lastname` varchar(25) COLLATE utf8_unicode_ci NOT NULL,
`dob` date NOT NULL,
`adult` enum('YES','NO') COLLATE utf8_unicode_ci NOT NULL DEFAULT 'NO',
`mobile` text COLLATE utf8_unicode_ci NOT NULL,
`landline` text COLLATE utf8_unicode_ci NOT NULL,
`address` text COLLATE utf8_unicode_ci NOT NULL,
`email` text COLLATE utf8_unicode_ci NOT NULL,
`comments` longtext COLLATE utf8_unicode_ci NOT NULL,
`timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-- Dumping data for table `cbdb_contacts`
--
INSERT INTO `cbdb_contacts` (`contactID`, `firstname`, `lastname`, `dob`, `adult`, `mobile`, `landline`, `address`, `email`, `comments`, `timestamp`) VALUES
(38, 'Tex', 'Brown', '2020-06-01', 'NO', '', '', '', '', '', '2020-07-12 18:34:19'),
(39, 'Mary', 'Brown', '2020-06-01', 'YES', '', '', '', '', '', '2020-07-06 19:03:23'),
(40, 'Pamela', 'Brown', '2020-06-01', 'YES', '', '', '', '', '', '2020-07-08 08:13:11'),
(41, 'Eddy', 'Green', '2020-06-01', 'NO', '', '', '', '', '', '2020-07-06 19:04:19'),
(42, 'Sheila', 'White', '2020-06-01', 'NO', '', '', '', '', '', '2020-07-12 18:54:03'),
(43, 'Dan', 'Black', '2020-06-01', 'NO', '', '', '', '', '', '2020-07-08 08:20:25'),
(134, 'Annete', 'Pray', '0000-00-00', 'NO', '', '', '', '', '', '2020-07-12 19:23:02'),
(133, 'Alex', 'Grey', '0000-00-00', 'NO', '', '', '', '', '', '2020-07-12 19:10:14'),
(132, 'Princess', 'Brown', '0000-00-00', 'NO', '', '', '', '', '', '2020-07-11 22:43:55'),
(131, 'Prince', 'Black', '0000-00-00', 'NO', '', '', '', '', '', '2020-07-11 22:39:22'),
(129, 'Tom', 'Smith', '0000-00-00', 'YES', '', '', '', '', '', '2020-07-11 22:34:32'),
(128, 'James', 'Dean', '0000-00-00', 'YES', '', '', '', '', '', '2020-07-11 22:14:19'),
(127, 'Peter', 'Paul', '0000-00-00', 'NO', '', '', '', '', '', '2020-07-11 22:08:52'),
(130, 'Tess', 'Logan', '0000-00-00', 'NO', '', '', '', '', '', '2020-07-11 22:38:35');
--
-- Indexes for dumped tables
--
--
-- Indexes for table `cbdb_contacts`
--
ALTER TABLE `cbdb_contacts`
ADD PRIMARY KEY (`contactID`),
ADD KEY `firstname` (`firstname`) USING BTREE;
--
-- AUTO_INCREMENT for dumped tables
--
--
-- AUTO_INCREMENT for table `cbdb_contacts`
--
ALTER TABLE `cbdb_contacts`
MODIFY `contactID` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=135;
COMMIT;发布于 2020-07-12 15:13:06
默认情况下,当使用getCollection()时,缓存似乎是启用的,请尝试将false作为第三个参数传递。
$collections = $modx->getCollection($class, null, false);您可能还必须将一个空数组作为第二个参数传递,文档有点矛盾。
$collections = $modx->getCollection($class, [], false);编辑
显然,片段结果也是缓存的,甚至不会访问数据库,除非使用非缓存语法[[!tag]]调用它们。使用!指令应该绕过这个特定片段的缓存,这是可以的,因为这是最小的数据库查询。
https://stackoverflow.com/questions/62800367
复制相似问题