The Manual»Developing with CakePHP»Components»Creating Components»Using other Components in your Component
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() {
// ...
}
}
?>
<?phpclass CustomComponent extends Object {var $name = 'Custom'; // the name of your componentvar $components = array('Existing'); // the other component your component usesfunction initialize(&$controller) {$this->Existing->foo();}function bar() {// ...}}?>
<?php
class ExistingComponent extends Object {
var $name = 'Existing';
function initialize(&$controller) {
$this->Parent->bar();
}
function foo() {
// ...
}
}
?> <?phpclass ExistingComponent extends Object {var $name = 'Existing';function initialize(&$controller) {$this->Parent->bar();}function foo() {// ...}}?>
