cakephp-3.8 - 为什么我的插件没有在生产中加载?
问题描述
我需要在我的应用程序的联系表单中实现 Google reCaptcha,所以我尝试安装一个简单的 reCaptcha 插件(这个插件似乎很简单:https ://github.com/agiletechvn/Recaptcha )。所以我按照说明进行操作。
我用 composer 安装它,用 bin/cake 插件加载它,验证有一个“$this->addPlugin('Recaptcha');” 在我的 Application.php 中并对我的控制器和视图进行了适当的更改。在 localhost 中,一切似乎都运行良好(并且 debugkit 告诉我插件正在正确加载),但是作为一个 reCaptcha 我无法测试它,除非它是一个实时服务器。所以我上传了所有文件(包括 vendor 中的相应文件夹和更新 cakephp-plugins.php 文件)。问题是它一直给我一个“找不到组件类 RecaptchaComponent”。错误。我错过了什么或放错了什么?
我的控制器:
class ClientsController extends AppController
{
public function initialize() {
parent::initialize();
$this->loadComponent('Recaptcha.Recaptcha', [
'enable' => true,
'sitekey' => '6Lf2xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', //the sitekey I got from the Google reCaptcha API
'secret' => '6Lf2xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', //the secret key I got from the Google reCaptcha API
'type' => 'image',
'theme' => 'light',
'lang' => 'en',
'size' => 'compact'
]);
}
public function contact()
{
$client = $this->Clients->newEntity();
if ($this->request->is('post')) {
if ($this->Recaptcha->verify()) {
$client = $this->Clients->patchEntity($client, $this->request->getData());
if ($this->Clients->save($client)) {
$this->Flash->success('Your message has been saved.');
$this->redirect($this->referer());
} else {
$this->Flash->error('There was a problem with the Contact Form. Please retry.');
$this->redirect($this->referer());
}
} else {
$this->Flash->error('Verify the Google Recaptcha before continuing.');
}
}
$this->set(compact('client'));
}
}
我的观点:
<?= $this->Form->create($client); ?>
<?= $this->Form->control('first_name',['label' => 'Firt name:']); ?>
<?= $this->Form->control('last_name',['label' => 'Last name:']); ?>
<?= $this->Form->control('email', ['label' => 'Email:']) ?>
<?= $this->Form->control('phone', ['label' => 'Phone number:']) ?>
<?= $this->Form->control('comments', ['label' => 'Message:','rows' => 3]) ?>
<?= $this->Recaptcha->display(); ?>
<?= $this->Form->button('Send') ?>
<?= $this->Form->end(); ?>
我得到的错误:
错误:[Cake\Controller\Exception\MissingComponentException] 找不到组件类 RecaptchaComponent。(/home1/viajejuw/public_html/vendor/cakephp/cakephp/src/Controller/ComponentRegistry.php:101)
免责声明:我在生产服务器中没有可用的终端连接。
解决方案
听起来您可能没有上传更新的自动加载器文件。不要只传输选定的供应商文件,如果您没有 shell 访问权限并且无法在服务器上运行 composer,您应该传输所有供应商文件,除非您有一种防故障方法来跟踪哪些文件已被更改。
在 10 次中有 9 次在目标环境中缺少一个类但它存在于本地环境中的情况下,该文件要么没有上传,要么具有错误的权限,不存在于自动加载器中,要么存在拼写错误这与区分大小写的文件系统不兼容。
推荐阅读
- xml - 如何在chart.apis.google 链接中使用变量以获取二维码
- vue.js - 如何在 Live Server 中上传 Vue.js 项目
- r - 在 x 轴上对齐 geom_jitter 点并将 y 视为频率
- security - Api Gateway 上的 AWS 资源策略:匿名无权对具有显式拒绝的资源执行调用
- powershell - Powershell:在用户存储中查找证书,基于模板
- android - 如何在非 AndroidX 应用程序中集成任何 AndroidX SDK
- r - 在ggplot2中将geom_text与geom_boxplot对齐
- java - 当 Java 对象仍然与强引用和弱引用链接时,它是 gc-ed
- swift - “移动指令指针可能会导致意外行为,包括使您的应用程序崩溃。” 线程1:断点1.1
- django - 当我试图从 Django 管理界面中删除时,'str' 对象不可调用?