JERC
JERC

Reputation: 1624

Parameters and my own functions in symfony2

Hi to every one I'm new with symfony2, and i got two questions,

the first is: I need have 2 Parameters in one array, for example

   $actions = array('1' => 'In', '2' => 'Out')

in all symfony2 in my bundle, where is the appropriate place/file to set this parameter, I've seen in symfony 1.4 put this parameter in some classes but in symfony2 I dont know wherw to put it because I just have the Entity DIR for classes.

The second is:

I need create my own functions to do something about a entity class for example Employees, I need to create a function to get the a especific employe and after do some proccess with its information a return a value, well the question is
Where I should put my own functions in my bundle ?

Any Suggestion I appreciate it!!!

Upvotes: 0

Views: 378

Answers (1)

jkucharovic
jkucharovic

Reputation: 4244

Answer to 2nd question: Symfony2 uses ClassLoader so if you will follow coding standards, you can put it anywhere, you want to (I recommend you to read best practises). Just register namespace:

namespace Acme\TestBundle\Temp;

class MyClass
{
  public function getCertainEmployee($param)
  {}
}

One of possible way is to use EntityRepository.

namespace Acme\TestBundle\Entity;

use Doctrine\ORM\EntityRepository;

class EmployeeRepository extends EntityRepository
{
  public function getCertainEmployee($param)
  {}
}

The you can just call:

$certainEmployee = $this->getDoctrine()
                        ->getEntityRepository('AcmeTestBundle:Employee')
                        ->getCertainEmployee($foo)
;

Upvotes: 1

Related Questions