2014-07-13 42 views
0

我想要顯示的日期作爲DMY:例如1975年7月7日CakePHP的:警告(2):用htmlspecialchars()預計參數4是布爾

但是與此代碼:

<?php echo h($player['Player']['player_birthDate'], array('dateFormat'=>'DMY')); ?> 

我得到的錯誤信息:

Warning (2): htmlspecialchars() expects parameter 4 to be boolean, array given [CORE\Cake\basics.php, line 198] 

htmlspecialchars - [internal], line ?? 
h - CORE\Cake\basics.php, line 198 
include - APP\View\Players\index.ctp, line 34 
View::_evaluate() - CORE\Cake\View\View.php, line 935 
View::_render() - CORE\Cake\View\View.php, line 897 
View::render() - CORE\Cake\View\View.php, line 466 
Controller::render() - CORE\Cake\Controller\Controller.php, line 952 
Dispatcher::_invoke() - CORE\Cake\Routing\Dispatcher.php, line 192 
Dispatcher::dispatch() - CORE\Cake\Routing\Dispatcher.php, line 160 
require - APP\webroot\index.php, line 108 
[main] - ROOT\index.php, line 41 

型號:

'player_birthDate' => array(
    'date' => array(
     'rule' => array('date'), 
    ), 
), 
+0

這是預期的行爲,沒有什麼值得驚訝的** [API參考> h()](http://api.cakephp.org/2.5/function-h。 html)**您是否檢查過文檔以尋求解決方案? ** [Cookbook> TimeHelper :: format()](http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#TimeHelper::format)** – ndm

回答

1

它是用PHP日期函數一樣

<?php echo date('d-m-Y',strtotime($player['Player']['player_birthDate'])); ?> 
0

您可以使用Timehelper類格式的日期和時間最簡單的方法: - 在控制器

public $helpers = array('Time'); 

打印

負荷時間幫手格式化日期在視圖中

echo h($this->Time->format('2011-08-22 11:53:00','%A-%B-%Y')); 

輸出: - 2011年8月1日星期一

相關問題