【发布时间】:2015-01-12 05:14:07
【问题描述】:
所以我在前端使用AngularJS,在后端使用SlimPHP 和REST url。我正在尝试使用VisualCaptch,我按照PHP端的说明进行操作,它似乎在后端工作,我做了一个简单的Angular dataService调用url并将其显示在控制台上,但我根本不明白如何将它与 Angular 连接,我也下载了该部分,但是当我创建 HTML 并在 <div> 中调用 captcha 时。好吧,实际上让我解释一下问题的 1,它是 Angular 试图运行的 url 不正确,但我只是不知道如何配置它,有选项吗?所以让我展示一下我目前拥有的代码...顺便说一下,我使用Controller as vm 语法,所以你不会在我的代码中找到$scope。
HTML:
<div captcha options="vm.captchaOptions"></div>
AngularJS 控制器代码:
// this work as a dataService call to SlimPHP
dataService.getCaptchaHowMany().then(function(data) {
console.debug(data);
});
// where does my dataService call goes in here???
vm.captchaOptions = {
imgPath: 'vendors/visual-captcha/img/',
captcha: { numberOfImages: 5 },
init: function ( captcha ) {
vm.captcha = captcha;
}
};
SlimPHP 路由,我知道它们可以工作
# Captcha Routes
$app->get('/captcha/start/:howMany', function($howMany) use ($app) { CaptchaController::getCaptchaHowMany($app, $howMany); });
$app->get('/captcha/audio(/:type)', function($type = 'mp3') use ($app) { CaptchaController::getCatpchaDiskAudioStreaming($app, $type); });
$app->get('/captcha/image/:index', function($index) use ($app) { CaptchaController::getCatpchaDiskImageStreaming($app, $index); });
$app->post('/captcha/try', function() use ($app) { CaptchaController::postCatchaTryValidate($app); });
当我使用 Angular 复制 VisualCaptcha 的示例并运行代码时,它显示了错误的 url 调用(因为我的 SlimPHP Api 位于不同的位置而导致错误)。所以错误的 url 调用看起来像这样:
GET http://localhost/myproject/user/start/5
但是要正确调用我的SlimPHP Api 路由,它应该是这样的GET http://localhost/myproject/api/captcha/start/5
那么我应该在哪里使用 VisualCaptcha 为 Angular 配置路由???我还附上了我正确 url 的结果,所以我认为我的后端(SlimPHP)工作正常,只是在控制器中配置了错误的 Angular url。
编辑
我现在走得更远了,我发现我们可以在 captchaOptions 内设置 url,现在可以正确调用我的SlimPHP api url 如下
vm.captchaOptions = {
imgPath: 'vendors/visual-captcha/img/',
captcha: {
numberOfImages: 5,
url: 'api/captcha'
},
// use init callback to get captcha object
init: function ( captcha ) {
vm.captcha = captcha;
}
};
我现在遇到的问题是它不显示图像。图片是假设来自 PHP 还是来自客户端的 Angular?哪个文件夹应该包含所有图像?我实际上在控制台中收到此错误消息:
HTTP "Content-Type" of "text/html" is not supported. Load of media resource http://localhost/investing/api/captcha/audio?r=353oeaysbjg failed.
我实际上不想要音频,虽然它给了我这个音频错误,我只是想使用图像,仅此而已。谁能帮帮我,拜托!
【问题讨论】:
标签: javascript php angularjs captcha slim