2014-03-07 25 views
0

我有與Joomla Calendar form field類型的問題,這是我的代碼:日期格式問題的Joomla

<field name="date" type="calendar" label="Date (*)" 
      class="inputbox required" size="22" 
      format="%Y-%m-%d" labelclass="control-label" readonly="true" default="NOW" 
     /> 

我所試圖做的是設置默認值設置爲當前日期在這個字段,但它顯示了像這樣的默認值2014-03-07 00:00:00,但我不想在這個領域顯示時間,正如你可以看到我已經定義了格式"%Y-%m-%d",但不知道爲什麼它顯示,如果有一些有任何解決方案爲此,請幫助。

回答

0

試試這個,

格式(可選)是要使用的日期格式。這是PHP用來指定日期字符串格式的格式(見下文)。如果沒有給出格式參數,則假定'%Y-%m-%d'(給出諸如'2008-04-16'的日期)。

閱讀more

如果上述情況沒有作品再試試下面的方法。

在你的XML

<field name="date" type="PubDateCalendar" label="Date (*)" 
      class="inputbox required" size="22" 
      format="%Y-%m-%d" labelclass="control-label" readonly="true" 
     /> 

場/ pubdatecalendar.php

<?php 
defined('_JEXEC') or die; 
jimport('joomla.form.helper'); 
JFormHelper::loadFieldClass('calendar'); 

class JFormFieldPubDateCalendar extends JFormFieldCalendar 
{ 
    public $type = 'PubDateCalendar'; 
    protected function getInput() 
    { 

     $this->value = date('Y-m-d'); 

     return parent::getInput(); 
    } 
} 
?> 

希望其作品..

+1

都能跟得上它仍然顯示了同樣的 – Toretto

+0

秒選項也? –

+0

是的兩個選項都沒有工作 – Toretto

0

試試這個...這個代碼和@Jobin何塞之間的區別上面的解決方案是你稱之爲家長的地方。展望JFormFieldCalendar類節目是ovveride有自己的格式

<?php 

defined('_JEXEC') or die; 
jimport('joomla.form.helper'); 
JFormHelper::loadFieldClass('calendar'); 

class JFormFieldCustomCalendar extends JFormFieldCalendar 
{ 

    public $type = 'CustomCalendar'; 

    protected $defaultFormat = 'd-m-Y'; 

    /* 
    * Un jour d'intervalle entre le debut et la fin 
    */ 
    protected $interval = 'P1D'; 

    protected function getInput() 
    { 
     parent::getInput(); 

     // Build the attributes array. 
     $attributes = array(); 

     empty($this->size)  ? null : $attributes['size'] = $this->size; 
     empty($this->maxlength) ? null : $attributes['maxlength'] = $this->maxlength; 
     empty($this->class)  ? null : $attributes['class'] = $this->class; 
     !$this->readonly  ? null : $attributes['readonly'] = ''; 
     !$this->disabled  ? null : $attributes['disabled'] = ''; 
     empty($this->onchange) ? null : $attributes['onchange'] = $this->onchange; 
     empty($hint)   ? null : $attributes['placeholder'] = $hint; 
     $this->autocomplete  ? null : $attributes['autocomplete'] = 'off'; 
     !$this->autofocus  ? null : $attributes['autofocus'] = ''; 

     if ($this->required) { 
      $attributes['required'] = ''; 
      $attributes['aria-required'] = 'true'; 
     } 

     $date = new DateTime("now"); 

     $format = $this->element['format'] ? (string) $this->element['format'] : $this->defaultFormat; 
     $validFormat = preg_replace('/%/', '', $format); 

     if ($this->element['default'] == 'start') { 
      $this->value = $date->format($validFormat); 
     } else if ($this->element['default'] == 'end') { 
      $date->add(new DateInterval($this->interval)); 

      $this->value = $date->format($validFormat); 
     } 

     return JHtml::_('calendar', $this->value, $this->name, $this->id, $format, $attributes); 
    } 

}