草庐IT

php - Slim 路由中的 HttpBasicAuth

我正在尝试使用BasicHttpAuth验证特定的Slim路由SlimExtras中的中间件这可行,但是它需要所有路由进行身份验证:$app=newSlim();$app->add(newHttpBasicAuth('username','password'));$app->get('/',function()use($app){$app->render('index.php');});$app->get('/admin',function()use($app){$app->render('admin.php');});$app->run();那么如何使用HttpBasicAuth对单

php - Slim + NotORM,选择 %Like%

刚开始使用Slim框架+NotORM_,需要做以下工作:SELECT*FROMUsersWHEREnameLIKE'%$value%'"在Slim中,我可以使用选择完全匹配的行$p=$db->Users()->where('name',$value)as$p)如果有人告诉我解决我问题的正确方法,我将不胜感激 最佳答案 您可以在查询中使用通配符提供like关键字,并在PHP中的搜索词前后添加%符号,如下所示:$p=$db->Users()->where('namelike?',"%$value%")

php - 获取 Slim Post 请求值

这段代码;$email=$app->request('custom1');print_r($email);exit;会给予;Slim_Http_RequestObject([method:protected]=>POST[headers:protected]=>Array([host]=>192.168.56.101[connection]=>keep-alive[content-length]=>26[cache-control]=>no-cache[origin]=>chrome-extension://fhbjgbiflinjbdggehcddcbncdddomop[conten

php - Slim3/DRY - 如何在不重复代码的情况下正确处理错误/异常?

我正在使用Slim3开发一个相当大的JSONAPI。我的Controller/操作目前充斥着以下内容:return$response->withJson(['status'=>'error','data'=>null,'message'=>'Usernameorpasswordwasincorrect']);在应用程序的某些点上,任何事情都可能出错,响应需要适当。但有一点很常见,就是错误响应总是相同的。status始终是error,data是可选的(在表单验证错误的情况下,data将包含那些)并且message设置为向API的用户或消费者指示出了什么问题。我闻到了代码重复的味道。如何减

php - 将路由组织成单独的文件,在 Slim 中无法正常工作

这是我的Index.php文件:use\Psr\Http\Message\ServerRequestInterfaceasRequest;use\Psr\Http\Message\ResponseInterfaceasResponse;require'../vendor/autoload.php';require'../src/config/db.php';$app=new\Slim\App;//UserRoutesrequire'../src/routes/users.php';//Thisnotworkingrequire'../src/routes/org.php';//Only

php - Ajax + JSON 解码 + Slim PHP 问题?

好吧,我似乎无法从我的ajax调用中解码JSON,它将用户数据发布到我的api,它是用slimphp构建的..这是我的ajax..varjsonData;jsonData=[{username:"user",password:"pass"}];$.ajax({type:"POST",url:"http://localhost/api/user/auth",data:{user:JSON.stringify(jsonData)},contentType:"application/json;charset=utf-8",dataType:"json",success:function(da

php - 如何使用 Slim 接受所有 REST URI 中的排序和分页参数?

我正在使用SlimPHP框架为我的应用程序创建一个RESTfulAPI。我希望所有URL都能够接受用于排序和分页的参数。谁能告诉我执行此操作的最佳方法?此外,有人可以为此提供一些适当的RESTURI吗?(即http://domain.com/api/category/fruit/?sort=DESC&results=25&page=2)get('/wines',function()use($app){$sort=$app->request()->params('sort');$results=$app->request()->params('results');$page=$app->

php - 使用 Slim 框架和 Twig 模板时出错

我正在尝试让Slim与Twig模板系统一起工作,这是我的index.php的一部分//Twig[Template]require'Extras/Views/Twig.php';TwigView::$twigDirectory=__DIR__.'/vendor/Twig/lib/Twig/';//Slimrequire'Slim/Slim.php';\Slim\Slim::registerAutoloader();$app=new\Slim\Slim(array('view'=>$twigView));这是我的结构Extras|_Views|_Twig.phpSlimtemplatesv

php - Slim - 从浏览器调用端点工作正常,而从 PHPUnit 测试调用端点返回 404

我正在使用PHPUnit@http://there4development.com/blog/2013/10/13/unit-testing-slim-framework-applications-with-phpunit/关注Slim的测试设置最初我的所有逻辑都在匿名函数中$app->get('/video/',function()use($app){//allcodegoeshere}通过PHPUnit进行测试效果很好...publicfunctiontestVideoCountInPage1(){$this->get('/video/');$this->assertEquals(

javascript - CORS 在 php slim 框架中不工作

我使用phpslim框架创建了restapi。这是我的代码post('/messagebhej(/)(:profile_id/?)(:app_auth_token/?)','messagebhej');$app->post('/login','login');$app->run();functionmessagebhej($profile_id,$app_auth_token){$error='';$request=file_get_contents('php://input');try{$request_data=json_decode($request,true);if($app_