Whoops! nothing to see there

3.6.4.3 Using other Components in your Component

Sometimes one of your components may need to use another.

You can include other components in your component the exact same way you include them in controllers: Use the $components var.

<?php
class CustomComponent extends Object {
    var $name = 'Custom'; // the name of your component
    var $components = array('Existing'); // the other component your component uses

    function initialize(&$controller) {
        $this->Existing->foo();
    }

    function bar() {
        // ...
   }
}
?>
  1. <?php
  2. class CustomComponent extends Object {
  3. var $name = 'Custom'; // the name of your component
  4. var $components = array('Existing'); // the other component your component uses
  5. function initialize(&$controller) {
  6. $this->Existing->foo();
  7. }
  8. function bar() {
  9. // ...
  10. }
  11. }
  12. ?>
<?php
class ExistingComponent extends Object {
    var $name = 'Existing';

    function initialize(&$controller) {
        $this->Parent->bar();
    }
 
    function foo() {
        // ...
   }
}
?>
  1. <?php
  2. class ExistingComponent extends Object {
  3. var $name = 'Existing';
  4. function initialize(&$controller) {
  5. $this->Parent->bar();
  6. }
  7. function foo() {
  8. // ...
  9. }
  10. }
  11. ?>