我正在向服务器发送一个AJAx请求,以查询与某个类别“目的地”相关的所有“属性”。
条目中的字段名为Destination,其句柄为“destinationCategories”
我的代码目前看起来像这样;
public function actionGetLocation()
{
$locationId = craft()->request->getParam('id');
// Find the Actual Category Object from The DB, I did this just in case I need to query based on title, or something else
// The correct category is being returned
$criteria = craft()->elements->getCriteria(ElementType::Category);
$criteria->id = $locationId;
$criteria->limit = null;
$selectedCategory = $criteria->first();
unset($criteria);
$criteria = craft()->elements->getCriteria(ElementType::Entry);
// I am now attempting to query for
// destinationCategories = the category that I have queried from the DB
$criteria->destinationCategories = $selectedCategory->id;
$criteria->limit = null;
$properties = $criteria->find();
var_dump($properties);
foreach($properties as $property)
{
echo $property->title;
}
exit;
return $this->returnJson(array('status' => 'ok', 'options' => $subCategories));
}
即使结果可用,查询也会返回null
我在哪里出错我试过
$criteria->destinationCategories = $selectedCategory->id;
$criteria->destinationCategories = $selectedCategory->title;
$criteria->destinationCategories = $selectedCategory->slug;
答案 0 :(得分:-1)
我想您可能到目前为止已经完成了这个项目:),但是要解决此问题,您可以尝试在使用任何依赖变量之前不要取消设置$ criteria。使用完毕后,请取消设置变量。