Topic: write and read json files

I want to write a plugin for calendar events in json and wonder if monstra has the option to convert the timestamp  in date and time  or doing it in simple php

I hope that me you understand.

..::: Moncho Varela ::::..   ..::: @Nakome ::::..   ..::: Github ::::..

nakome's Website

Re: write and read json files

Sorry, I cant understand.

doc about write and read files http://monstra.org/documentation/file-helper

Monstra Loves You! Give some love back!

Re: write and read json files

Please, you can write  an example to read and write json in storage.

I have a problem with a plugin, if I put the file in any folder, you can read it, but if I put it in storage does not read and do not understand that, and when you want to write the opposite

..::: Moncho Varela ::::..   ..::: @Nakome ::::..   ..::: Github ::::..

nakome's Website

Re: write and read json files

well I already write the json but I rewrites the code and the dos2unix does not give me the exact date

This is my code.

// file path
$jsonfile =  STORAGE . DS . 'events' . DS .'../../post/924/events.js';
// Request
if (Request::post('Event_date')) $Event_date  =  Request::post('Event_date');  else $Event_date = '';
if (Request::post('Event_hour')) $Event_hour  =  Request::post('Event_hour');  else $Event_hour = '';
if (Request::post('Event_title'))$Event_title =  Request::post('Event_title'); else $Event_title = '';
if (Request::post('Event_text')) $Event_text  =  Request::post('Event_text');  else $Event_text = '';
if (Request::post('Event_url'))  $Event_url  =  Request::post('Event_url');    else $Event_url = '';
// Timestamp
$date = Date::dos2unix( first problem);
$data[] = array(
        'date' => $date, 
        'type' => "meeting",  
        'title' =>  $Event_title, 
        'description' => $Event_text, 
        'url' => $Event_url    
        );
// Add events
if(Request::post('Events_add')){    
    File::setContent( $jsonfile , str_replace('\/','/',json_encode($data)));          
}    
// Output
[
   {
        "date":312764480,
        "type":"meeting",
         "title":"Banana joe",
         "description":"Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.",
         "url":"http://nakome.16mb.com"
    }
]
..::: Moncho Varela ::::..   ..::: @Nakome ::::..   ..::: Github ::::..

nakome's Website

Re: write and read json files

nakome, okey, is everthing Ok now ? or you have some other questions ?

Monstra Loves You! Give some love back!

Re: write and read json files

The problem is that rewrites, no adds  and, date not working well.

..::: Moncho Varela ::::..   ..::: @Nakome ::::..   ..::: Github ::::..

nakome's Website

Re: write and read json files

I've managed to generate the data in this way:

// file path
$jsonfile = STORAGE . DS . 'events/events.txt';
if (Request::post('Event_date')) $Event_date  =  Request::post('Event_date');  else $Event_date = '';
if (Request::post('Event_title'))$Event_title =  Request::post('Event_title'); else $Event_title = '';
if (Request::post('Event_text')) $Event_text  =  Request::post('Event_text');  else $Event_text = '';
if (Request::post('Event_url'))  $Event_url  =  Request::post('Event_url');    else $Event_url = '';
// timestamp 
$date = Date::dos2unix($Event_date);
$data = array(
    'date' => $date,
    'title' =>  $Event_title,
    'description' => $Event_text,
    'url' => $Event_url
);
if(Request::post('Events_add')){
    File::setContent(
          $jsonfile , 
          str_replace('\/','/', 
              json_encode( $data )
           ),
          $create_file = true,  
          $append = true
    );
    Notification::set('success', 'success');             
}    

But, i have a problem,

How can I change this :

{
  date:"1211353200000",
   title:"CoABoardMeeting",
  description:"Thereisnodescription.",
  url:"events_details.php?page=body&ID=1"
}
{
  date:"1211353200000",
  title:"CoABoardMeeting",
  description:"Thereisnodescription.",
  url:"events_details.php?page=body&ID=1"
}


For this:

[
{
  date:"1211353200000",
  title:"CoABoardMeeting",
  description:"Thereisnodescription.",
  url:"events_details.php?page=body&ID=1"
},
{
  date:"1211353200000",
  title:"CoABoardMeeting",
  description:"Thereisnodescription.",
  url:"events_details.php?page=body&ID=1"
}
]
..::: Moncho Varela ::::..   ..::: @Nakome ::::..   ..::: Github ::::..

nakome's Website

Re: write and read json files

I cant imagen how this can work)

    File::setContent(
          $jsonfile , 
          str_replace('\/','/', 
              json_encode( $data )
           ),
          $create_file = true,  
          $append = true
    );

Correct variant is:

    File::setContent(
          $jsonfile , 
          str_replace('\/','/', 
              json_encode( $data )
           ),
          true,  
          true
    );
Monstra Loves You! Give some love back!

Re: write and read json files

Yes, but  works ,but what I cannot do is the other.

..::: Moncho Varela ::::..   ..::: @Nakome ::::..   ..::: Github ::::..

nakome's Website