我正在尝试学习如何使用工作流程组件
在DefaultController.py中的这一行(远远低于):
$service->apply($loginMessage, 'message_shown');
我收到了消息
Neither the property "marking" nor one of the methods "getMarking()", "marking()", "isMarking()", "hasMarking()", "__get()" exist and have public access in class "UserFlowBundle\Entity\LoginMessage".
500 Internal Server Error - NoSuchPropertyException
可能导致错误的原因是什么?我的代码与SFLive Example非常相似,我看不出有什么区别。
LoginModal.php
<?php
namespace UserFlowBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* LoginMessage
*
* @ORM\Table(name="login_message")
* @ORM\Entity(repositoryClass="UserFlowBundle\Repository\LoginMessageRepository")
*/
class LoginMessage
{
public function __construct($user)
{
$this->user = $user;
$this->state = 'none';
}
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="state", type="string", length=255)
*/
private $state;
/**
* @var string
*
* @ORM\Column(name="user", type="string", length=255, unique=true)
*/
private $user;
/**
* Get id
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Set state
*
* @param string $state
*
* @return LoginMessage
*/
public function setState($state)
{
$this->state = $state;
return $this;
}
/**
* Get state
*
* @return string
*/
public function getState()
{
return $this->state;
}
/**
* Set user
*
* @param string $user
*
* @return LoginMessage
*/
public function setUser($user)
{
$this->user = $user;
return $this;
}
/**
* Get user
*
* @return string
*/
public function getUser()
{
return $this->user;
}
}
DefaultController.py
<?php
namespace UserFlowBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\HttpFoundation\Request;
/**
* @Route("/userflow")
*/
class DefaultController extends Controller
{
/**
* @Route("/")
*/
public function indexAction()
{
$user = $this->get('security.token_storage')->getToken()->getUser();
return $this->render('UserFlowBundle:Default:index.html.twig', ['user'=>$user]);
}
/**
* @Route("/apply-transition/", name="user_flow_apply_transition")
* @Method("POST")
*/
public function applyTransitionAction(Request $request)
{
try {
$user = $this->get('security.token_storage')->getToken()->getUser();
$em = $this->get('doctrine')->getManager();
$repository = $em->getRepository('UserFlowBundle:LoginMessage');
$loginMessage = $repository->findOneOrCreateByUser($user);
$service = $this->get('state_machine.loginModal');
$service->apply($loginMessage, 'message_shown');
#$service->apply($loginMessage, $request->request->get('transition'));
$this->get('doctrine')->getManager()->flush();
} catch (ExceptionInterface $e) {
$this->get('session')->getFlashBag()->add('danger', $e->getMessage());
}
return $this->redirect(
$this->generateUrl('task_show', ['id' => 1])
);
}
}
答案 0 :(得分:1)
我对工作流程组件不太熟悉,但我对symfony非常熟悉。
在查看https://github.com/lyrixx/SFLive-Paris2016-Workflow/blob/master/src/AppBundle/Entity/Task.php后,我发现,您还没有声明方法getMarking
和setMarking
,这也是错误消息所说的内容。
我有根据的猜测是,工作流程组件需要某种标记来告诉它,实体处于哪种状态。
答案 1 :(得分:1)
如Symfony文档所述:
marking_store选项的类型(默认值single_state)和参数(默认值 marking )属性是可选的。如果省略,将使用其默认值。
如果state属性未命名为“ marking”,则可以这样配置它:
# config/packages/workflow.yaml
framework:
workflows:
my_workflow:
type: 'state_machine'
marking_store:
type: 'single_state'
arguments:
- 'myStateProperty'
support:
- App\Entity\MyEntity