CakePHP 的generateTreeList()
方法允许您选择返回的键和值。例如,如果您希望返回一个以 slug 作为键并以链接文本作为值的列表,则可以使用$keyPath
and$valuePath
参数来实现:
$data = $this->Category->generateTreeList(null, "{n}.Category.slug", "{n}.Category.text", '_');
debug($data); die;
可能会产生:
array(
["my-categories"] => "My Categories",
["fun"] => "_Fun",
["sport"] => "__Sport",
["surfing"] => "___Surfing",
["skating"] => "___Skating",
["friends"] => "__Friends",
["gerald"] => "___Gerald",
["gwendolyn"] => "___Gwendolyn",
["work"] => "_Work",
["trips"] => "__Trips",
["national"] => "___National",
["international"] => "___International",
["other-peoples-categories"] => "Other People's Categories",
["extreme-fishing"] => "_Extreme fishing"
)