【问题标题】:Laravel 4: redirect not workingLaravel 4:重定向不起作用
【发布时间】:2014-03-06 12:45:02
【问题描述】:

首先,让我们进入应用程序的上下文:

我们在 CustomerController 上,这是一个 Resource Controller 向 Store 方法发送一个 post 请求。

这是我的存储方法:

$customerDTO = new \repositories\dtos\CreateCustomerDTO();
$customerDTO->hydrate( Input::All() );

/** @var Customer $customer */
$customer = $this->customers->create( $customerDTO );

if ( $customer != null ){
    header('Location: '.url('/customers/'.$customer->clacli));
    return Redirect::action('CustomerController@show', array($customer->id) );
}

$userMessage = array(
    'messageType' => 'error',
    'messageContent' => 'Error creating a new Customer'
);

return Redirect::action('CustomerController@index')
    ->with(array('userMessage' => $userMessage));

我不得不添加一个“标题”,因为重定向调用不起作用。

当我把这行:

$customer = $this->customers->create( $customerDTO );

所有重定向都停止工作。

$this->customers 里面是什么?它只是一个从控制器中抽象数据库的存储库,我将需要在不久的将来更改数据库。

嗯,$this->customers->create 里面的代码是:

return Customer::create( $dto->toArray() );

它正在运行,我的 customersRepository 的所有测试也正在运行。这只是使用数据数组调用 Eloquent Model create 方法。

所以我无法弄清楚为什么重定向不起作用。有什么建议吗?

我尝试使用 return 'test';就在调用 $this->customers->create($customerDTO); 之后也没有工作。

【问题讨论】:

  • dd($customer)$customer = $this->customers->create( $customerDTO ); 之后显示什么?
  • 使用Redirect::action的时候,是不是需要对应那个控制器的路由?这可能是我没有使用过的一种重定向类型,所以我不是 100%。
  • 对象(客户)#325 (20) ...等
  • 不是重定向,而是响应。返回“文本”;也不行

标签: php laravel


【解决方案1】:

会话出现了一个奇怪的问题。我们修复了它,不知道为什么......

【讨论】:

    猜你喜欢
    • 2014-04-18
    • 1970-01-01
    • 2014-05-31
    • 2014-01-09
    • 1970-01-01
    • 1970-01-01
    • 2014-03-05
    • 2012-09-13
    • 1970-01-01
    相关资源
    最近更新 更多