Felix
Felix

Reputation: 5619

TYPO3 call a class from controller

I wanna call a seperate Class from my Controller.

The class is found under: Classes/Domain/Services I wanna call only a getter!

The class I wanna call is named TestClass.php

In my controller I tried: $this->view->assign('options', $this->TestClass->getTest());

The Testclass looks like this:

class NoteArrays {
    protected $tests= array(        
       'a' => 'a',        
       'b' => 'b');

    public function getTest() {        
       return $this->tests;   
    }
}

But I've got only a blank page....

Upvotes: 3

Views: 433

Answers (1)

Felix
Felix

Reputation: 5619

Soution is:

namespace Test\Test\Services\NestedDirectory; 

class NoteArrays { 

       protected $tests= array( 'a' => 'a', 'b' => 'b'); 

       public function getTest() { 
             return $this->tests; 
       } 
} 

And to create and assign:

$array = new \Test\Test\Services\NestedDirectory\NoteArrays(); 
$this->view->assign('options', $array->getTest()); 

Upvotes: 2

Related Questions