0

呼び出されたコンポーネントが独自のactions::functionnameを使用している別のモジュールで、コンポーネントを呼び出すのに苦労しています。

例えば

module / user / アクション/actions.class.phpにはgetUserName()のような関数があります同じモジュールのコンポーネントでuserActions :: getUserName()関数を呼び出しています。

ファイル:module / user /アクション/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()のような関数を呼び出している場合、他のモジュールのコンポーネントを呼び出すことはできません

4

1 に答える 1

0

ユーザー セッションで作業している場合は、レイアウト テンプレートで直接アクセスすることができます ( http://symfony.com/legacy/doc/gentle-introduction/1_4/en/06-Inside-theのユーザー セッション セクションを参照)。 -コントローラー層):

<?php echo $sf_user->getAttribute('nickname') ?>

それ以外の場合、変数をコンポーネントに渡すには ( http://symfony.com/legacy/doc/gentle-introduction/1_4/en/07-Inside-the-View-Layerのコンポーネントセクションを参照):

[リスト 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' 
于 2013-03-25T19:53:21.560 に答える