⚠ In case you've missed it we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This forum is read-only and soon will be archived. ⚠


Carlos Castell

Member Since 26 Mar 2015
Offline Last Active Sep 17 2015 06:08 AM
-----

Posts I've Made

In Topic: read state doesn't use the configured date format

08 April 2015 - 09:47 PM

I have assumed that the read state will never format the date so I decided to do it myself by modifying the read.php file under assets\grocery_crud\themes\datatables\views.

 

You just need to add the below code in the div that prints the values out, around line 34.

 

Before the change:

<div class='form-input-box' id="<?php echo $field->field_name; ?>_input_box">
<?php echo $input_fields[$field->field_name]->input?>

After the change:

				<div class='form-input-box' id="<?php echo $field->field_name; ?>_input_box">
					<?php 
						$res = preg_match('/[0-9]{4}\-[0-9]{2}\-[0-9]{2}/',$input_fields[$field->field_name]->input,$var);
						if($res==1) {
							if(!preg_match('/0000/',$var[0])) {
								$ci = &get_instance();
								$dt = new DateTime($var[0]);
								$output = $dt->format($ci->config->item('grocery_crud_default_date_format'));
								$res = preg_match('/[0-9]{4}\-[0-9]{2}\-[0-9]{2}\s[0-2][0-9]\:[0-6][0-9]/',$input_fields[$field->field_name]->input,$var);
								if($res==1) {
									$dt = new DateTime($var[0]);
									$output = $dt->format($ci->config->item('grocery_crud_default_datetime_format'));
								}
								echo $output;
							} else 
								echo "";
						} else
							echo $input_fields[$field->field_name]->input?>

Now you can test the date format in the read state... and make sure you have defined the format you want in the application/config/grocery_crud.php file, I used:

 

$config['grocery_crud_default_date_format']  = 'd M Y';

$config['grocery_crud_default_datetime_format'] = 'd M Y - H:i';

 

Cheers!


In Topic: Query builder in grocery?

07 April 2015 - 09:36 PM

Thanks Amit,

 

You're right, I think I will have to do it outside grocery crud... just wanted to make sure there was nothing already done for that.