Welcome Guest, Not a member yet? Register   Sign In
Reformat date from CURRENT_TIMESTAMP
#11

(02-24-2020, 08:29 AM)MikiStoni Wrote:
(02-23-2020, 09:47 PM)John_Betong Wrote: @MikiStoni,
> unfortunately not. the parser seems not to be able to read the date correctly

I am not a fan of using any parser and have never heard an argument that has convinced me to change my mind.

Try the following:

Code:
<tr>
  <th scope="row">
    <?php date('d.m.y H:i:s', $timestamp); ?>
  </th> 
</tr> 


is surely a matter of taste. i like to use parsers. for me it is more tidy. i create an array and pass it to the template. the foreach and formatting is done in the template. i always used smarty. and with ci4 i wanted to eliminate smarty. but simple functions like formatting date or substr functions are unfortunately not supported.

by the way, your code does not work, because i pass the data as an array. variables in parser are only readable with brackets {}

I assumed that the $timestamp variable was an actual UNIX timestamp (integer seconds since 1970...) and not a string. 

Please try the following:
Code:
var_dump($timestamp);
// or 
echo gettype($timestamp); 

Perhaps renaming $timestamp to $datetime would be easier for others when the variable types are not declared in the function parameters. Reminds me of calling apples oranges and vice-versa Smile
Reply
#12

Hi zahhar

doesn't work for me.

My Controll

Code:
    helper('changetable');
    // get ma permission name
    $data = [
      'ma_perm_name'          => permission2name(session('userData.permission')),
      'breadcrump_nav_big'    => 'Mein Profil',
      'breadcrump_nav_low'    => 'Profile',
      'changetable'           => changetable_get(session('userData.id'), 'changetable'),
    ];

    // view template
    echo $parser->setData($data)->renderString(view('profile'));


My Profile

Code:
                {changetable}

                  <tr>
                    <th scope="row">{timestamp|date(d.m.Y H:i:s)}</th>
                    <td>{message}</td>
                  </tr>

                {/changetable}


My Helper

Code:
if (!function_exists('changetable_get')) {
    /**
    * Get changes in changetable table
    */
    function changetable_get($ma, $table) {

        // get log
        $db       = \Config\Database::connect();
        $builder  = $db->table($table);
        $builder->orderBy('timestamp', 'DESC');
        $query    = $builder->get(50);

        return $query->getResult();

    }

}

Result:

Code:
{changetable} {/changetable}
{timestamp|date(d.m.Y H:i:s)}     {message}

funny thing Smile
Reply
#13

(02-26-2020, 04:08 AM)MikiStoni Wrote: Hi zahhar

doesn't work for me.

Code:
{changetable} {/changetable}
{timestamp|date(d.m.Y H:i:s)}     {message}

funny thing Smile

MikiStoni, this is how you could proceed:
1) ensure you have changes in system/View/Parser.php class as proposed here: https://github.com/codeigniter4/CodeIgni...2603/files
2) take my example and ensure it works for you. You should start wikth smth really simple.

Regarding your code: it most probably would not work. In order to work, you should populate {changetable} variable with array of arrays.
You can try the following: try to supply static data into changetable variable in your $data array first, like this:

PHP Code:
'changetable' => [
                   ['message' => 'My message''timestamp' => '2020-02-26 00:00:00']
               

Then show what you get.
Reply
#14
Thumbs Up 
(This post was last modified: 02-29-2020, 02:57 AM by MikiStoni.)

You're right. If I input that directly, it works.

with the further use of the class i found out that no provided filter works for me if a bracket belongs to it.

work:

Code:
                    <td>{ message|prose }</td>
                    <td>{ message|capitalize }</td>
                    <td>{ message|abs }</td>

does not work:

Code:
                    <td>{ message|limit_chars(100) }</td>
                    <td>{ message|limit_words(20) }</td>
                    <td>{ message|number_format(3) }</td>

does anyone know the problem?
Reply




Theme © iAndrew 2016 - Forum software by © MyBB