I'm new to cakephp, I've got a simple Users controller that corresponds to a users table. I have a created field in the table that I want to ouput on the view action using the niceShort() function. how do I use it in the view?
Current code is:
<p>Member since <?php echo $user['User']['created']?></p>
thanks,
Jonesy
use Cake\I18n\Time; // Create from a string datetime. $time = Time::createFromFormat( 'Y-m-d H:i:s', $datetime, 'America/New_York' ); // Create from a timestamp $time = Time::createFromTimestamp($ts); // Get the current time.
In the controller you can include the build in time helper:
users_controllee.php:
var $helpers = array('Time');
In the view:
<p>Member since <?php echo $time->niceShort($user['User']['created']); ?></p>
Just use built in php function date.
You can use it like this:
echo date('d.m.Y', strtotime($user['User']['created']));
You can use any format you like for date formatting based on build in patterns.
http://php.net/manual/en/function.date.php
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With