0
私はmartyshka/ShoppingCartコンポーネントを実装しようとしています。私が見つけたのは、アイテムを追加している間にハイドレーターがヌルだったのですが、強制したときには(コンポーネントに設定すると)機能しませんでした。martyshka/ShoppingCart ZF2コンポーネントが動作しないのはなぜですか(ハイドレーターの問題かもしれません)?
<?php
namespace Publico\Controller;
use Doctrine\ORM\EntityManager;
use ShoppingCart\Controller\Plugin\ShoppingCart;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
class CarrinhoController extends AbstractActionController
{
private $carrinho;
private $entityManager;
protected function setCarrinho(ShoppingCart $cart)
{
$this->carrinho = $cart;
return $this;
}
protected function getCarrinho()
{
if (null === $this->carrinho) {
$this->setCarrinho(new ShoppingCart());
}
return $this->carrinho;
}
/*...*/
public function indexAction()
{
try {
$carrinho = $this->getCarrinho();
} catch (\Exception $e) {
die($e->getMessage());
}
$carrinhoItems = [
'carrinho' => $carrinho->cart(),
'valorTotal' => $carrinho->total_sum(),
'qtdTotal' => $carrinho->total_items(),
];
die($carrinhoItems);
return new ViewModel([
'carrinho' => $this->carrinho->cart(),
'valorTotal' => $this->carrinho->total_sum(),
'qtdTotal' => $this->carrinho->total_items(),
]);
}
/*...*/
}
をそれを使用しています。 ありがとうございます。 –
@SalustianoMuniz偉大な、知っておいて、私はまた、同じ問題がいくつかの時間前に立ち往生していた。 –