我知道在触发动作之前/之后会有事件发生.
在调用控制器之前,堆栈中是否有更高的值?
在期间Zend_Controller_Action::init(),有没有办法取消行动(因此不会被调用)?
<?php
class JsonApiController extends Zend_Controller_Action {
function init()
{
// try JSON decoding the raw request body
if ($jsonDecodingFailed) {
echo '{"error":"invalid JSON"}';
$this->_cancelAction(); // something like this exist?
}
}
}
Run Code Online (Sandbox Code Playgroud)
我目前的解决方法是创建一个空nullAction()方法并调用$this->_forward('null')转发它.
每当我从模型或控制器发送邮件时,我都会遇到问题.事情是在我使用的控制器中
这是关于PHP的.
在控制器中:
if (Post::get()){
$this->model->registerUser( ... );
$this->model->mailSendUserActivation();
// assign something to view.
}
Run Code Online (Sandbox Code Playgroud)
在模型中:
public function mailSendUserActivation(){
$mail = new \com\Mail();
// assign stuff to mail from API classes and other functions in model.
$mail->send();
}
Run Code Online (Sandbox Code Playgroud)
它是否正确 ?或者邮件真的应该从控制器发送?
Resharper 6有一个非常好的新功能:如果我在MVC3项目的任何地方编写RedirectToAction或Html.Action,它会加下划线并使用ctrl-click我可以在那里导航.如果不存在此类操作,它也会通知我.
但是,我在BaseController中有一个辅助方法,它接受一个额外的参数(放入TempData),然后调用RedirectToAction.不幸的是,Resharper不承认这些字符串是控制器和方法名称,并没有强调.
我使用与MVC相同的参数命名约定,我的返回类型是相同的,但仍然没有.MVC的方法是否可能被硬编码到Resharper中?有没有办法让它也适用于我的方法?

我正在实现REST Web API.我使用Adam Freeman的Pro ASP.NET MVC5中的示例作为起点,但将其调整为Web API的方式.
以下是我的代码:
public class AdminController : ApiController
{
private IUserRepository _repository;
public AdminController(IUserRepository repository)
{
_repository = repository;
}
public ActionResult Index()
{
return View(_repository.Users);
}
}
Run Code Online (Sandbox Code Playgroud)
在本书中,没有AdminController实现,但如果我这样做,那么我会得到关于没有无参数构造函数的错误.我需要构造函数来获取参数,以便我可以注入依赖项.所以这就是我改变的原因,但现在却无法识别.ControllerApiControllerApiControllerView
我需要做什么来代替使用View一个ApiController?
我确实找到了这个问题,但答案基本上是"你不需要在这里使用ApiController,只需使用Controller",这样就没有帮助我.
我正在编写一个服务,其中我接受一个ID或一个位置,并且我想强制执行约束,即必须在我的@Controller中指定ID或位置
@Controller
public class HelloController {
@RequestMapping(value="/loc.json",method = RequestMethod.GET)
public @ResponseBody String localiaztionRequest(@RequestParam(value = "location", required = false) String callback
,@RequestParam(value = "id", required = false) String uuid
,@RequestParam(value = "callback", required = false) String callback) {
//model.addAttribute("message", "Hello world!");
return "hello";
}
Run Code Online (Sandbox Code Playgroud)
为了清楚起见,我希望每个请求都发送location参数或id参数。如何对一对输入参数施加这样的约束?另外,有人可以向我解释ModelMap的用法,model.addAttribute(“ message”,“ Hello World!”)有什么作用?抱歉,如果这些问题看起来太幼稚,那么我对Spring框架是陌生的。
提前致谢。
我正在尝试实现以下目的:在RSpec Controller测试中创建一个POST json请求,并将其传递给params.这是我的代码
it 'returns access_token' do
post :login, email: 'bla', password: 'bla1', format: :json
end
Run Code Online (Sandbox Code Playgroud)
我在控制器中获得的请求.body.read是一个带有params的字符串,但是像这样传递
email=bla&password=bla1
这绝对不是JSON.但是,如果我使用CURL提出请求
curl -d '{"email": "bla@bla.com" }' http://127.0.0.1:3000/users/login --header "Accept: application/json" --header "Content-Type: application/json"
我把request.body.read作为正确的json
"{\"email\": \"bla@bla.com\", \"password\": \"bla1\" }"
那么如何从我的rspec传递这种方式呢?
我正在使用Laravel 5.0内置身份验证控制器.但是,除了进行身份验证之外,我还想在登录期间添加一些操作,例如更新另一个表.我似乎无法找到我应该写这样的代码的地方.
对于注册,我在"服务"文件夹下的"Registrar.php"文件中添加了我想要的内容.我怎么能登录?
提前致谢.
我想为Symfony中的所有控制器创建一个基本控制器类,我是Symfony的新手,所以不要对愚蠢的问题生气.我问这个问题,因为我不能做这样的事情
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
class AbstractController extends Controller
{
public function __construct()
{
//...... check access level
$user = $this->getUser(); //This is not working, I don't have access to the Controller(the base class) properties
}
}
Run Code Online (Sandbox Code Playgroud)
现在我的一个控制器
class UserController extends AbstractController
{
public deleteUserAction(Request $request)
{
var_dump($this);// this will dump an empty class that is not instance of Symfony\Bundle\FrameworkBundle\Controller\Controller
//.... delete user
}
}
Run Code Online (Sandbox Code Playgroud)
做这个的最好方式是什么?请...编辑....我真正想要做的是检查用户权限级别是否足以访问特定控制器中的特定操作(例如deleteUserAction())(例如UserController),我有一个类将权限级别附加到所有控制器中的所有操作.如果它发生在父控制器(例如BaseController的构造函数)中,那么检查将非常有效,该控制器之前执行UserController->deleteUserAction()但在基本控制器中我无法访问$ this.我试过选民和ACL没有人帮助我的情况.提前致谢.
我正在开发我的第一个Spring Boot应用程序,我遇到了一个奇怪的问题.配置非常基础:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.pawsec</groupId>
<artifactId>kitchen</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>kitchen</name>
<description>The Kitchen restaurant system</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.pawsec</groupId>
<artifactId>common</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<executable>true</executable>
</configuration>
</plugin>
</plugins>
</build>
</project>
Run Code Online (Sandbox Code Playgroud)
我们在调用这两个服务的页面上有一些Javascript代码.当控制器在第一个方法中返回Guy对象时,我们得到一个空响应:
{data: …Run Code Online (Sandbox Code Playgroud) controller ×10
php ×4
asp.net-mvc ×2
asp.net ×1
c# ×1
jackson ×1
java ×1
javascript ×1
json ×1
laravel ×1
laravel-5 ×1
model ×1
php-5.3 ×1
request ×1
resharper ×1
rspec ×1
spring-boot ×1
spring-mvc ×1
symfony ×1
testing ×1
web-services ×1