markdown 模特管理员

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown 模特管理员相关的知识,希望对你有一定的参考价值。

#### Add sortable to ModelAdmin
For adding to newly created DataObject [Here](https://github.com/UndefinedOffset/SortableGridField/blob/master/docs/ModelAdminExample.md)  
For adding to existing DataObject: [Here](http://www.silverstrip.es/blog/sorting-in-modeladmin/)  
```
<?php
 
class NavigationAdmin extends ModelAdmin
{
 
    private static $managed_models = array(
        'NavigationItem'
    );
    private static $url_segment = 'nav-items';
    private static $menu_title = 'Navigation';
 
    public function getEditForm($id = null, $fields = null)
    {
        $form = parent::getEditForm($id, $fields);
        // $gridFieldName is generated from the ModelClass, eg if the Class 'Product'
        // is managed by this ModelAdmin, the GridField for it will also be named 'Product'
        if (class_exists('GridFieldOrderableRows')) {
            $gridFieldName = $this->sanitiseClassName($this->modelClass);
            if ($gridFieldName == 'NavigationItem' && array_key_exists('Sort',
                    DataObject::database_fields('NavigationItem'))
            ) {
                $gridField = $form->Fields()->fieldByName($gridFieldName);
                $gridField->getConfig()->addComponent(new GridFieldOrderableRows());
            }
        }
 
        return $form;
    }
 
}
```
```
<?php
 
class NavigationItem extends DataObject
{
 
    private static $singular_name = 'Navigation Item';
    private static $plural_name = 'Navigation Items';
 
    private static $db = array(
        'Title' => 'Varchar(255)',
        'Active' => 'Boolean',
        'Sort' => 'Int'
    );
 
    private static $has_one = array(
        'Link' => 'SiteTree'
    );
 
    private static $default_sort = 'Sort';
 
    private static $summary_fields = array(
        'Title',
        'Link.Title',
        'Active.Nice'
    );
 
    private static $field_labels = array(
        'Title' => 'Title',
        'Link.Title' => 'Link',
        'Active.Nice' => 'Active'
    );
 
    public function getCMSFields()
    {
        $fields = parent::getCMSFields();
 
        $fields->removeByName(array(
            'Sort'
        ));
 
        return $fields;
    }
 
    protected function onBeforeWrite() {
        if (!$this->Sort) {
            $this->Sort = NavigationItem::get()->max('Sort') + 1;
        }
 
        parent::onBeforeWrite();
    }
 
    public function canCreate($member = null)
    {
        return true;
    }
 
    public function canEdit($member = null)
    {
        return true;
    }
 
    public function canDelete($member = null)
    {
        return true;
    }
 
    public function canView($member = null)
    {
        return true;
    }
 
}
```

以上是关于markdown 模特管理员的主要内容,如果未能解决你的问题,请参考以下文章

说店铺是模特对吗?

2023第八届少儿模特明星盛典 福州赛区 初赛圆满收官

IPA第八届少儿模特明星盛典 福州赛区 初赛圆满收官

2023第八届少儿模特明星盛典 濮阳赛区 海选赛圆满落幕

IPA第八届少儿模特明星盛典 福州赛区 初赛圆满收官

IPA第八届少儿模特明星盛典 濮阳赛区 海选赛圆满落幕