私は、単一のブロックタイプの “skillLevels”という名前のMatrixフィールドを持っています。
各行には2つのフィールド「skillName」と「skillLevel」があります。
skillNameは別のエントリとの関係です(スキル) skillLevelは単純な整数です。
私はフォームから投稿データを取るカスタムプラグインを構築しています。 フォームには、エントリID($
groupId)、スキル名、およびスキルのレベルを変更するために使用する値が含まれています。
$groupEntry = craft()->entries->getEntryById($groupId);
$skillLevels = $groupEntry->skillLevels;
foreach($skillLevels as $skill){
$skillLevel = $skill->skillLevel;//outputs the skill level
$skillName = $skill->skillName;//this doesn't work
}
$skill->$skillLevel
gives me the integer stored
in that field. But $skill->skillLevel
does not
gives me a model. I then tried using $skill->skillLevel->id
but still no luck.
フォームの投稿データから得られるスキル名と一致する行を見つけるために、行列の行を調べるにはどうすればよいですか?
Your skillName
is a object of type
ElementCriteriaModel
so it is just a query. In order
to fetch the element you need to do
$skill->skillName->first()
エントリを取得する方法とelementCriteriaModelがどのように機能するかについてのドキュメントを読むべきです。
Edit: your $skillLevels
and your
$skill->skillName
are both the same type of
objects. Both are ready to use queries that have a iterable
interface. So when you loop through them (like you do) the
find()
method is executed which returns you all the
populated query results. You don’t load all relations for an entry
when you do getEntryById
– you get just queries you
can execute