2017-03-11 59 views
1

我創建了一個選項「perPage」組成,即acept的數量和設置每頁作品顯示器的限制...十月CMS |如何從安裝在特定頁面上的組件獲取屬性值?

enter image description here

public function defineProperties() 
    { 
     return [ 
      'perPage' => [ 
       'title' => 'Number os works per page', 
       'description' => 'How many works do you want to display per page?', 
       'default' => 9, 
       'validationPattern' => '^[0-9]+$', 
       'validationMessage' => 'Only numbers allowed' 
      ], 
      'sortOrder' => [ 
       'title' => 'Order of Works', 
       'description' => 'How do you want to order the actors', 
       'type' => 'dropdown', 
       'default' => 'newest', 
      ], 
     ]; 
    } 

它工作,GET實現的大...但在我的項目中,我需要在任何地方實現AJAX,所以我需要通過AJAX加載頁面,並且我需要知道在組件上設置了多少個數字......我如何獲得這個數字?

//my layout code 
function onOpenWorkList() 
{ 

    $this['works'] = Category::where('slug', input('slug'))->first(); 

    $this['categories'] = Category::all(); 

    $this['active_category'] = input('slug'); 

    $this['perPage'] = ""; // HERE IS THE CODE 

    return [ 
     '.home_categories' => $this->renderPartial('work_list_categories_post'), 
     '.container' => $this->renderPartial('work_list') 
    ]; 
} 

enter image description here

+1

代碼粘貼文本沒有圖像 – C2486

回答

0

在您的組件文件:

public $perPage; 

/* ... */ 

public function init() 
{ 
    $this->perPage = $this->property('perPage'); 
} 

然後,在佈局,你可以這樣做:

function onOpenWorkList() 
{ 
    $this['works'] = Category::where('slug', input('slug'))->first(); 

    $this['categories'] = Category::all(); 

    $this['active_category'] = input('slug'); 

    $_component = $this->components['builderList']; // Get the component 

    $this['perPage'] = $_component->perPage; // Get $perPage from component 

    return [ 
     '.home_categories' => $this->renderPartial('work_list_categories_post'), 
     '.container' => $this->renderPartial('work_list') 
    ]; 
} 

就個人而言,我只想把onOpenWorkList()功能集成到組件文件中(而不是在佈局代碼中),因爲它可以起作用通過ajax進行訪問時,它就像在上面的例子中一樣容易,然後你就不必取得組件。

+0

你好,是的,我知道的..但它是一個組件配置文件內的作品......我需要外界得到這個值,我不能在我的佈局中添加此代碼代碼文件:P –

+1

@IvanDunets對不起,我誤解了你最初的問題。我已經更新了我的答案。 – Joseph

+0

我在A:\ xampp \ htdocs \ framastudio \ storage \ cms \ cache \ 50 \ 74 \ default.htm.php的第26行中得到一個錯誤「」未定義索引:worksList「(worksList是組件的別名:)) –

相關問題