Cakephp:在组件中加载组件 [英] Cakephp: Load components in components
问题描述
在app_controller.php中加载会话,Auth组件。
in app_controller.php load Session, Auth components.
在posts_controller.php中,我使用CustomComponent和$ components = array('Session','Auth');
And in posts_controller.php, i use CustomComponent with $components = array('Session','Auth');
那么CustomComponent必须重新加载Session,Auth组件吗?
Then do CustomComponent must reload Session, Auth components?
如果我使用并创建了很多组件使用其他组件。它会使应用程序非常缓慢吗?
if i use and create much components and that components use other components .It will make app is very slow?
我在cakephp IRC中问过,
I asked in cakephp IRC, A person answer is not:
[11:05]它不会很慢,我相信它通过引用传递这些
[11:05] it will not be slow, I believe it passes those around via reference
[11:05]因此您无需担心
[11:05] so you have nothing to worry about
推荐答案
假设您要将AComponent导入BComponent。
Lets say you want to import AComponent into BComponent.
AComponent
AComponent
class AComponent extends Component {
public $components = array('BComponent');
public function xyz(){
$test = $this->BComponent->abc($name);
echo $test;
}
}
BComponent
BComponent
class BComponent extends Component {
public function abc($name){
return "My name is: ". $name;
}
}
这篇关于Cakephp:在组件中加载组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!