web-dev-qa-db-ja.com

モデルから、ビューで取得したデータにどのようにアクセスできますか?

外部情報をコンポーネントに追加しようとしていますが、view.html.phpのデータを取得しています。取得したら、モデルでどのように使用できますか?私は思いつく限りの多くの通常の変数を試しましたが、成功しませんでした。 $thisJModelAdminの拡張)の中に埋め込まれているのがわかりますが、その方法を見つけることができます。

example\view.html.php

public function display($tpl = null) {
    $this->state    = $this->get('State');
    $this->item     = $this->get('Item');
    $this->form     = $this->get('Form');
    $this->MyInfo   = $this->get(MyInfo);  // Use $this->item to get my info

models\example.php:

public function getItem($pk = null) {
    if (!$item = parent::getItem($pk))
    {
        throw new Exception('Failed to load item');
    }
    return $item;
}

public function getMyInfo($pk = null)
{
    // Need some of the data from `$this->item` already retrieved in function `display`
    // Do some SQL here

    return $mydata;
}
2
Al Knight

Get関数から親を試してください

public function getMyInfo($pk = null)
{
   $myItem = parent::getItem($pk);
   echo $myItem->myfieldname;
   .
   .
   .
2
GDP