通过ajax调用phcon php MVC控制器。

时间:2022-12-01 23:21:02

i am using simple app with phalcon PHP and AngularJs. i am trying to call my phalcon PHP controller from angularJS controller through AJAX POST request.

我使用的是一个简单的应用程序,有phalcon PHP和AngularJs。我试图通过AJAX POST请求从angularJS控制器调用我的phalcon PHP控制器。

 $http.post('/ControllerName/', {params});

and i get

我得到

404 The requested URL /ControllerName/ was not found on this server

在此服务器上没有找到请求的URL /ControllerName/。

i think my request is being routed to my public folder whereas my php controller is located in Non-public folder.

我想我的请求被路由到我的公用文件夹,而我的php控制器位于非公用文件夹中。

these are the .htaccess rules i have

这些是。htaccess规则。

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule  ^$ public/    [L]
RewriteRule  (.*) public/$1 [L]</IfModule>

and in the public folder:

在公用文件夹中:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?_url=/$1 [QSA,L]</IfModule>

what am i doing wrong?

我做错了什么?

2 个解决方案

#1


4  

Ok, My problem was in the rewrite mechanism as i thought. First, in httpd.conf file i had to:

我的问题是在重写机制中。首先,在httpd。conf文件我必须:

  1. Change "AllowOverride None" to "AllowOverride All" in the relevant directory.
  2. 在相关目录中更改“AllowOverride None”到“AllowOverride All”。
  3. My "mod_rewrite" was disabled, so i had to un-comment the line: "# LoadModule rewrite_module modules/mod_rewrite.so"
  4. 我的“mod_rewrite”被禁用了,所以我不得不取消注释:“# LoadModule rewrite_module模块/ mod_rewriteso”。

#2


0  

On the assumption you are using a default and working deployment of phalcon I suggest you to check for trailing slashes, there is a manual voice about that: http://docs.phalconphp.com/en/latest/reference/routing.html anchor #dealing-with-extra-trailing-slashes

假设您正在使用一个默认的和工作部署的phalcon,我建议您检查一下拖后的斜杠,这里有一个关于这个的人工语音:http://docs.phalconphp.com/en/latest/reference/routing.html anchor #dealing- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

you can also test your routes with a custom script: same url before, anchor #testing-your-routes

您也可以使用自定义脚本测试您的路由:之前的url,锚#测试-您的路线。

... or.. you can put your nose into the routing system to try to find where the failure is by listening on dispatcher for dispatch:beforeDispatchLoop, there is a piece of code here http://docs.phalconphp.com/en/latest/reference/dispatching.html#inject-model-instances, you can see in the event function how the framework would guess the controller and action names:

…或. .您可以将您的nose放到路由系统中,以尝试查找失败的地方,通过侦听dispatcher进行分派:beforeDispatchLoop,这里有一段代码:http://docs.phalconphp.com/en/latest/reference/dispatch.html # inj- model-instances,您可以在事件函数中看到该框架如何猜测控制器和操作名称:

//Possible controller class name
$controllerName = Text::camelize($dispatcher->getControllerName()) . 'Controller';

//Possible method name
$actionName = $dispatcher->getActionName() . 'Action';

... they should then exists for a successful routing, btw refer to the example code

…然后,它们应该为一个成功的路由而存在,顺便说一下,这是一个示例代码。

#1


4  

Ok, My problem was in the rewrite mechanism as i thought. First, in httpd.conf file i had to:

我的问题是在重写机制中。首先,在httpd。conf文件我必须:

  1. Change "AllowOverride None" to "AllowOverride All" in the relevant directory.
  2. 在相关目录中更改“AllowOverride None”到“AllowOverride All”。
  3. My "mod_rewrite" was disabled, so i had to un-comment the line: "# LoadModule rewrite_module modules/mod_rewrite.so"
  4. 我的“mod_rewrite”被禁用了,所以我不得不取消注释:“# LoadModule rewrite_module模块/ mod_rewriteso”。

#2


0  

On the assumption you are using a default and working deployment of phalcon I suggest you to check for trailing slashes, there is a manual voice about that: http://docs.phalconphp.com/en/latest/reference/routing.html anchor #dealing-with-extra-trailing-slashes

假设您正在使用一个默认的和工作部署的phalcon,我建议您检查一下拖后的斜杠,这里有一个关于这个的人工语音:http://docs.phalconphp.com/en/latest/reference/routing.html anchor #dealing- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

you can also test your routes with a custom script: same url before, anchor #testing-your-routes

您也可以使用自定义脚本测试您的路由:之前的url,锚#测试-您的路线。

... or.. you can put your nose into the routing system to try to find where the failure is by listening on dispatcher for dispatch:beforeDispatchLoop, there is a piece of code here http://docs.phalconphp.com/en/latest/reference/dispatching.html#inject-model-instances, you can see in the event function how the framework would guess the controller and action names:

…或. .您可以将您的nose放到路由系统中,以尝试查找失败的地方,通过侦听dispatcher进行分派:beforeDispatchLoop,这里有一段代码:http://docs.phalconphp.com/en/latest/reference/dispatch.html # inj- model-instances,您可以在事件函数中看到该框架如何猜测控制器和操作名称:

//Possible controller class name
$controllerName = Text::camelize($dispatcher->getControllerName()) . 'Controller';

//Possible method name
$actionName = $dispatcher->getActionName() . 'Action';

... they should then exists for a successful routing, btw refer to the example code

…然后,它们应该为一个成功的路由而存在,顺便说一下,这是一个示例代码。