2.2. Getting a component

You can get a component by the s2get funcion. The class name that is the key to the component is specified by the argument of the s2get function.


class Service {}

class Action {
    public function setService(Service $service) {
        $this->service = $service;

$action = s2get('Action');

The execution result is as follows. The Service instance is injected to the Action instance.

% php quickstart005.php
object(Action)#26 (1) {
  object(Service)#39 (0) {

Please refer to the following "Registration of the component" when you name the component name to the component besides the class name.


This Example is located at "examples/quickstart/quickstart005.php".

© Copyright The Seasar Foundation and the others 2005-2010, all rights reserved.