从控制器调用实体方法

Calling an entity method from controller

我遇到以下问题。

我的HTMLAngular栏目

<button ng-click="setFollowed(store)" class="btn btn-default">Follow</button>

我的app.js

  .....
$scope.setFollowed = function(aStore){
    $http.put('/set-followed-store/aStore', { params: { aStore: aStore } }).success(function(data){
        alert(aStore.nombre);
    }).
    error(function(data, status, headers, config) {
                    alert(data);
    });
}

这很好用。

当我调用“set-followed-store/store”URL.

中的方法时出现问题

这是我在控制器中的方法,(我省略了 routing.yml,但它配置为触发此方法。)

    public function setFollowedStoreAction($aStore)
{
 
    $em = $this->getDoctrine()->getManager();
    
    $follower_store = $em->getRepository('AppBundle:Store')
                ->find($this->getUser()->getId());
      
    if(!$follower_store)
        throw $this->createNotFoundException('No store has been found with id: '.$this->getUser()->getId());
    
      
    $follower_store.addFollowedStore($aStore);
    
    $em->flush();
    
    return new Response('200 OK');
    
}

$follower_store.addFollowedStore($aStore);

给我以下错误,

Attempted to call function "addFollowedStore" from namespace "AppBundle\Controller". (500 Internal Server Error)

您应该使用 -> 而不是 . 来调用对象上的方法:

$follower_store->addFollowedStore($aStore);