0
我不是PHP開發人員(僅限Rails),但我有PHP代碼(thebuggenie-app)中的任務,它告訴我必須更改顯示select選項的順序。問題可能很簡單,但對我來說並不那麼容易。如何自定義陣列順序
我在PHP項目都看到我有這樣的事情,選擇(後小調查):
<optgroup label="<?php echo __('Globally available roles'); ?>">
<?php foreach ($global_roles as $role): ?>
<option value="<?php echo $role->getId(); ?>">
<?php echo $role>getName(); ?></option>
<?php endforeach ;?>
</optgroup>
和(可能)global_roles是將迭代一個數組。在Rails中很容易定製訂單,但這種情況我不知道。如果您需要任何信息,請告訴我。
在動作類,我發現:$this->global_roles = TBGRole::getAll();
這一個重定向我的腦海裏:
/**
* Returns all project roles available
*
* @return array
*/
public static function getAll()
{
return TBGListTypesTable::getTable()->getAllByItemTypeAndItemdata(self::ROLE, null);
}
現在我有開發商作爲第一選項(默認),我需要將測試儀作爲第一個(默認)選項
如果代碼可以工作,那麼每個解決方案都適合我:)
更新1)
public function getAllByItemTypeAndItemdata($itemtype, $itemdata)
{
$this->_populateItemCache();
$items = (array_key_exists($itemtype, self::$_item_cache)) ? self::$_item_cache[$itemtype] : array();
foreach ($items as $id => $item)
{
if ($item->getItemdata() != $itemdata) unset($items[$id]);
}
return $items;
}
這是更多的SQL問題。你能提供'getAllByItemTypeAndItemdata()'代碼嗎? – jaro1989
getAllByItemTypeAndItemdata()in update 1) – Skrypter