Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 740 Vote(s) - 3.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
formatting date string in cakephp

#1
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
Reply

#2
Just as point of reference the TimeHelper is CakePHP has a lot of nice stuff worth looking at

[To see links please register here]

Reply

#3
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.

[To see links please register here]

Reply

#4
I think darko is right.

You can simply use PHP function date() to format your date in any type.

Example :

`$date = date("Y-m-d H:i:s", strtotime($user['User']['created']));`

Here, strtotime() is the function of cakePHP to convert in datetime format.

Now you will have $date variable with a date formatted 'YYYY-mm-dd Hour:Minute:Second'.

For more option you can refer to PHP date manual :

[To see links please register here]


Hope this will be helpful to you...
Reply

#5
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>
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through