Symfony1.2组件问题

Symfony1.2组件问题,symfony1,components,partial,Symfony1,Components,Partial,我正在努力调用另一个模块中的组件,其中被调用的组件使用自己的操作::functionname 比如说 module/user/actions/actions.class.php具有类似getUserName()的函数 我在同一模块的组件中调用userActions::getUserName()函数,它工作正常,即 文件:module/user/actions/components.class.php public function executeShowUsername () { $this-&

我正在努力调用另一个模块中的组件,其中被调用的组件使用自己的操作::functionname

比如说

module/user/actions/actions.class.php具有类似getUserName()的函数 我在同一模块的组件中调用userActions::getUserName()函数,它工作正常,即

文件:module/user/actions/components.class.php

public function executeShowUsername () {
$this->userName =userActions::getUserName();
}
在组件的模板中(module/user/templates/_showUsername.php) echo$userName;(工作罚款)

现在,问题是: 在其他模块中包括('user','showUserName')组件时,如 文件:module/generate/template/indexSuccess.php

<?php include_component('user', 'showUserName'); ?>

我得到一个错误:

致命错误:在第86行的/myproject/apps/frontend/modules/user/actions/components.Class.php中找不到类“userActions”

我如何解决它? 如果其他模块中的组件正在调用类似的函数,我们不能调用它吗
userActions::getUserName()

如果您正在使用用户会话,您可以直接在布局模板中访问它(请参阅中的用户会话部分):

否则,要将变量传递给组件(请参见中的组件部分):

[来自清单7-13-将参数传递给组件及其模板]

// Call to the component
// rather than calling userActions::getUserName() in the component.class
// put your code from userActions::getUserName() into the model (or other accessible place)
// then call the component
<?php include_component('user', 'showUserName', array('MyUserName' => 'myuser')) ?>

// In the component itself
echo $this->MyUserName;
/* results in */ => 'myuser'

// In the _show_user_name.php partial
echo $MyUserName;
/* results in */ => 'myuser' 
//对组件的调用
//而不是在component.class中调用userActions::getUserName()
//将userActions::getUserName()中的代码放入模型(或其他可访问的位置)
//然后调用组件
//在组件本身中
echo$this->MyUserName;
/*结果为*/=>“myuser”
//在_show_user_name.php部分
echo$MyUserName;
/*结果为*/=>“myuser”

我没有使用会话,在上面的示例中,我只是实际使用了getUserName(),但如果我可以在任何其他模块中使用showUserName组件,这将对我有很大帮助。另外,我也不清楚为什么我需要将代码从全局访问类文件中转移到symfony1.2中我尝试支持的方式中?我认为您在组件中调用get userName()的方式与actions.class的方式不适用于框架的设计。这就是为什么我认为如果将getUserName()函数放在模型中,就可以在组件中访问它,并将其包含在其他模块中。希望这有帮助。