2

オブジェクトを作成しようとしていますが、値がデータベースに保存されません。プラグインは TypoScript を介して挿入され、実際には出力を作成しないため、これは「インデックス」アクションで行われます。そのため、アクションを呼び出すときにオブジェクトが指定されていないため、自分で作成しています。

$stat = new Tx_MyExt_Domain_Model_Stat;
$stat->setSubscriberId($_COOKIE['statid']);
$stat->setDomain($_SERVER['HTTP_HOST']);
$stat->setRequestUri($_SERVER['REQUEST_URI']);

$this->statRepository = t3lib_div::makeInstance('Tx_myExt_Domain_Repository_StatRepository');
$this->statRepository->add($stat);

を実行するvar_dump($stat)と、次のようになります。

object(Tx_MyExt_Domain_Model_Stat)#191 (9) {
  ["subscriber_id":protected]=>
  string(1) "2"
  ["domain":protected]=>
  string(22) "test.localhost.example"
  ["request_uri":protected]=>
  string(26) "/testpage/index.php?id=2"
  ["uid":protected]=>
  NULL
  ["_localizedUid":protected]=>
  NULL
  ["_languageUid":protected]=>
  NULL
  ["pid":protected]=>
  NULL
  ["_isClone":"Tx_Extbase_DomainObject_AbstractDomainObject":private]=>
  bool(false)
  ["_cleanProperties":"Tx_Extbase_DomainObject_AbstractDomainObject":private]=>
  NULL
}

したがって、これは値が適切に割り当てられているように見えます。しかし、データベースを調べると、次のようになります。

uid    pid    subscriber_id    domain    request_uri    crdate  
13     0      0                NULL      NULL           1328176026 

リポジトリ:

class Tx_MyExt_Domain_Repository_StatRepository extends Tx_Extbase_Persistence_Repository
{}

モデル:

class Tx_MyExt_Domain_Model_Stat extends Tx_Extbase_DomainObject_AbstractEntity 
{

    /**
     * @var int
     * @dontvalidate
     */
    protected $subscriber_id = 0;

    /**
     * @var string
     * @dontvalidate
     */
    protected $domain = '';

    /**
     * @var string
     * @dontvalidate
     */
    protected $request_uri = '';



    /**
     * @param int $susbcriber_id Subscriber id
     * @return void
     */
    public function setSubscriberId($subscriber_id) 
    {
        $this->subscriber_id = $subscriber_id;
    }

    /**
     * @return int Susbcriber id
     */
    public function getSubscriberId() 
    {
        return $this->subscriber_id;
    }

    /**
     * @param string $domain Domain
     * @return void
     */
    public function setDomain($domain)
    {
        $this->domain = $domain;
    }

    /**
     * @return string Domain
     */
    public function getDomain() 
    {
        return $this->domain;
    }

    /**
     * @param string $request_uri Request URI
     * @return void
     */
    public function setRequestUri($request_uri)
    {
        $this->request_uri = $request_uri;
    }

    /**
     * @return string Request URI
     */
    public function getRequestUri() 
    {
        return $this->request_uri;
    }

}

誰かがここで何が間違っているのか教えてもらえますか?

4

2 に答える 2

8

extbase プロセス全体を通してデバッグされます。typo3/sysext/extbase/Classes/Persistence/Backend.phpでは、次の行で属性がスキップされているようです。

if (!$dataMap->isPersistableProperty($propertyName) || $this->propertyValueIsLazyLoaded($propertyValue)) continue;

これは、$dataMap->isPersistableProperty($propertyName)何かを返さないためです。で調査するとtypo3/sysext/extbase/Classes/Persistence/Mapper、次のようなものがあります。

/**
 * Returns TRUE if the property is persistable (configured in $TCA)
 *
 * @param string $propertyName The property name
 * @return boolean TRUE if the property is persistable (configured in $TCA)
 */
public function isPersistableProperty($propertyName) {
    return isset($this->columnMaps[$propertyName]);
}

したがって、解決策は非常に簡単です。有効な TCA を作成します。私が使用しているテーブルはバックエンドに表示されないため、1つも持っていませんでした(または最小限にすぎません)。

于 2012-02-03T10:38:20.630 に答える
3

TCA の設定ミスが問題の原因である可能性がありますが、他にも問題がある可能性があります。たとえば、一意のキーを定義しているときに extbase が気に入らず、黙って失敗します。

複数のプロジェクトで問題が発生したため、拡張機能ビルダーで作成したプロジェクトに対して次のデバッグ ルーチンを使用しています。

  • テーブル関連のクラスとタイポスクリプトから独自の追加を削除します。これは、ext_tables.php、ext_tables.sql、Configuration/TCA および Configuration/Typoscript 内のすべてのファイルに対して実行する必要があります ( Configuration/ExtensionBuilder/settings.yamlでそれらの状態をマージまたは保持するように変更した場合)。

  • アプリケーションが保存されるかどうかを確認します。そうでない場合は、拡張機能ビルダーに詳細なバグ レポートを報告してください。

  • 通常、アプリケーションはすぐに保存されます。エラーが見つかるまで、行った変更を再帰的に読み取ります。ext_tables.sql から始めて (毎回データベースを削除して再読み込みする必要があることを忘れないでください)、ext_tables.php の Configuration/TCA/* に進み、Configuration/Typoscript で終わります (これらの順序が正しいのは私の個人的な経験です)。最速)

  • あなたのものをextbaseチームに報告し、このスレッドに追加してください(エラーが発生したときの最初のGoogleヒットであるため)

于 2012-03-24T09:53:32.037 に答える