[TYPO3-mvc] Findby* returns the exact number of objects but null

g4-lisz at tonarchiv.ch g4-lisz at tonarchiv.ch
Fri Dec 5 16:59:14 CET 2014


What do you get when you put the line

print_r($companies );
?
Looks to me like json_encode() can not handle that array for some reason...

Maybe that helps.

I just checked one of my extensions where a did some similar stuff. Look
at this code:
    public function messageAction($identifier, $type, $uid=NULL) {
        $messages = array();
        foreach( $this->messageRepository->findForApi($identifier,
$type, $uid) as $message) {
            $messages[] = array(
                'uid' => $message->getUid(),
                'title'=> $message->getTitle(),
                'subtitle' => $message->getSubtitle(),
                'text' => $message->getText(),
                'start' => $message->getStart(),
                'end' => ($message->getEnd());
        }
        return json_encode($messages);
    }

So it looks to me like I coudn't manage to pass the object directly to
json_encode(), neither. Sadly I can't remeber the reason why.
(Maybe I didn't know the toArray() method at that time?)

Cheers,
Till

On 12/05/2014 02:51 PM, RAKIBI Anass wrote:
> Hey ,
> my findbypay ( pay beeing here as a parameter) returns the exact
> number of entries in the database but the objects are null ...
>
> here is how I use it in an action :
>     public function getMyCompanysAction()
>         {
>             $argument  = $this->request->getArguments('id');
>             $companies = 
> $this->entrepriseRepository->findBypay(2)->toArray(); // just to test
> with the id 2
>             return json_encode($companies);
>         }
> the outputed json array contains 3 braces but is empty .. [{},{},{}].
> how could this really happen ? knowing that when I use the same method
> and assign it to the view , the objects are complete and I mean this
> way :
> public function listAction()
>         {
>
>            
>             $this->view->assign('lists',
> $this->entrepriseRepository->findBypays(2));
>         }
>
> _______________________________________________
> TYPO3-project-typo3v4mvc mailing list
> TYPO3-project-typo3v4mvc at lists.typo3.org
> http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-project-typo3v4mvc




More information about the TYPO3-project-typo3v4mvc mailing list