When I use the form helper to make a time input,usaually I write code as follows
<?php
$options = array(
'label' => '',
'type' => 'datetime',
'timeFormat'=>'24',
'separator'=>'-'
);
echo $form->input('Service.endtime',$options);
?>
But now I get a problem that I want to make a time input style such as
month-day-hour
Then how can do this with setting some parameters in the helper?Suggestions would be appreciated.
Well dateformat option will allow you to configure the date parts.
Used to specify the format of the select inputs for a date-related set of inputs. Valid values include ‘DMY’, ‘MDY’, ‘YMD’, and ‘NONE’.
http://book.cakephp.org/view/203/options-dateFormat
However for this I think that you will need to extend the helper and create a custom function which will return this mixed date and time style. Otherwise I can only think of having two selects, one with month and day, and one for hour. Then merging the data somewhere else, perhaps in beforeSave() or beforeValidate()
Hope my solution may help someone with the same requirement:
<?php
//echo $form->year('Modelname.year',2001,2021,intval(date('Y')),false)."-";
echo $form->month('Modelname.month',date('m'),'',false)."-";
echo $form->day('Modelname.day',date('d'))."-";
echo $form->hour('Modelname.hour',1,date('H'));
?>
Related
Is there anyway to modify the content shown in a SugarCRM Subpanel without relying on Action Hooks?
Right now to edit content for a Subpanel field I have to use the hooks like this...
$hook_array['process_record']
And in the Class method that I assign the Hook to call I can then change a field in the Subpanel like this...
$bean->name = '<a href="/index.php?action=ajaxui#ajaxUILoc=index.php%3Fmodule%3Dproje_Web_Project_Tasks%26action%3DDetailView%26record%3D'
.$bean->id.'" rel="popover" data-content="'
.$bean->description.'" data-original-title="">'.$bean->name.'</a>';
The main and major problem we have with this method is it works great until you do either of these actions....
Add an item using the Quick Create form
Change a page using the Subpanel paging buttons
In either case, it reloads the Subpanel data without running this hook code on the data, so the result is pretty major as the Subpanel fields that you have edited are no longer edited and show up as normal.
Here is a basic example...this shows 2-3 fields that have been edited using the Hook method above...
Now after paging or quick-creating a new record in the Subpanel, it reloads the Subpanel data and does not apply the Hooked code so you can see the result looks like this...
I know that ListView has a much more reliable and flexible method for editing it's content using the get_list_view_data() method I am able to apply the same edits and have them work all the time!
So I am hoping there is a similar method to edit Subpanel data and have it always apply the edits to that data? From what I have seen in my research so far, the only solution that will work as expected all the time, is to make a completely new Custom Field Type!
I am really hoping that is not the ONLY way as that is a major pain to do that for each type of field that I need to edit in the Subpanels and just doesn't feel right when there are easy ways to edit everything else except SubPanel data.
Does anyone have any ideas, suggestions, tips, help, please do share with me on this matter as it is the main problem I have had since I started developing with SugarCRM in the past few months?
You can change the data by writing a custom query to get data for your subpanel.
So inside your bean (this case Contacts) do a functions:
function get_project_list() {
$query = "SELECT project, info, matching, column, names FROM projects WHERE contact_id = '" . $this->id . "' AND deleted = 0"
return $query;
}
and then in subpanel definition set the data source like this:
$layout_defs["Contacts"]["subpanel_setup"]['projects'] = array(
'order' => 10,
'sort_order' => 'desc',
'sort_by' => 'name',
'title_key' => 'LBL_PROJECTS_TITLE',
'subpanel_name' => 'contact_projects',
'module'=>'projects',
'get_subpanel_data' => 'function:get_project_list',
'function_parameters'=>array('type'=>'urgent'), // this is optional if you decide to sent parameters to the function if do this dont forget to define your function with function get_project_list($params)
'top_buttons' => array (... buttons that you need go here..),
);
Since sql is quite powerful you can modify your subpanel data any way you like, well more or less :)
I want to check for a posted data if present so that I can set a form field as required or not, without having to create a custom rule.
Is it possible to use/load/call CodeIgniter's input library inside the config file (specifically the form_validation.php config file) and get user posted data without having to use the native $_POST variable?
my code goes something like this...
...
array(
'field' => 'dob_day',
'label' => 'Day',
'rules' => (($this->ci->input->post('include_person') === 'yes') ? 'required|' : '') . 'integer|max_length[2]|greater_than[0]|less_than[32]|valid_birth_date'
),
...
Obviously, my approach does not work. hehe. If there's an alternative efficient codeigniter way of doing what i'm thinking, please let me know.
Thanks for all your help! :)
See this:
MANUAL
try this example, in this mode you can at runtime change your rules:
$this->form_validation->set_rules('dob_day', 'Day', 'your new rules');
Okay, I ended up with putting the logic in the controller, and just using inline validation. But to have inline validation work without having to set all the rules, I used the code from this website to allow both inline and config rules to mix.
http://brettic.us/2010/09/13/codeigniter-form-validation-mix-rule/
Cheers!
I've a table where I set a field as TIMESTAMP, then I generate a module using tasks doctrine:generate-admin. By default Symfony creates a _form.php template where TIMESTAMP fields come separately as for example:
alumnos_fecha_ingreso_day
alumnos_fecha_ingreso_month
alumnos_fecha_ingreso_year
alumnos_fecha_ingreso_hour
alumnos_fecha_ingreso_minute
So in my template I've a field where values are entered as "dd/mm/yyyy" (is the default format) and I don't want to use Symfony way (it's ugly for end users). My question is how I deal with this value in order to get the right value and Symfony pass form validation? Is there any way to hide Hour and Minutes fields? Or is complety necessary?
If you just want day/month/year, you have to define the option with_time to false inside your form class.
with_time: Whether to include time (true by default)
And in your form:
$this->widgetSchema['my_date'] = new sfWidgetFormDateTime(array(
// I don't remember if you need to re-define the format
'date' => array('format' => '%day%/%month%/%year%'),
'with_time' => false
));
I have this field whose value i have to increment the field value by a specific value.
I am using this
$data['quantity'] = 'Order.quantity+1';
which doesnt works for me quantity is a integer coloumn here.
Also will it work when nothing is in database?.
Regards
Himanshu Sharma
I used updateAll in my code to increment views in an article. Therefore, every time an article is visited, I call the following function from within my view action in my articles controller:
function incrementViewCount($id) {
$this->updateAll(
array('Article.viewed' => 'Article.viewed+1'),
array('Article.id' => $id)
);
}
Then in your controller…
$this->MyModel->incrementViewCount(123);
Basically similar to the tutorial suggested in the previous answer.
you can use updateAll() for this
a little googling reveals this pretty quick:
http://cakephp.1045679.n5.nabble.com/Auto-Increment-A-Field-td3491697.html
You can try this code also. Works fine for simple ++/-- operations without the need of additional querying.
https://gist.github.com/denchev/8209318
Using saveField:
<?php
$this->Article->id = $id;
$this->Article->saveField('viewed', (int)$this->Article->field('viewed') + 1);
?>
I have a Yii dropdown which loads a table of cities, states, zipcodes, lat and lon. When loading the state dropdown, it takes forever. Is there a way to speed up the query to cut down on pageload time? I've included my view:
echo $form->dropDownList($model,'State', CHtml::listData(Zipcodes::model()->findAll(),
'State', 'State', 'State'), array('empty'=>'-- Choose State --'));
The table is 41,000 entries. Setting the $groupField in listData() didn't seem to give any noticeable improvements.
I think you can have two ways:
1) Use cache (with long or no expiration time, because this data you have are not dynamic).
First time your loading time will not change, but after that, it will bee much, much faster, because cache will be already saved.
http://www.yiiframework.com/doc/guide/1.1/en/caching.data#query-caching
$zipcodes = Zipcodes::model()->cache(3600*24*7)->findAll(); //cache for a week
Using cache you need to edit your config/main.php file
//...
'components' => array(
//...
'cache'=>array(
'class'=>'system.caching.CFileCache',
//'class'=>'system.caching.CDummyCache',
//other cache class
),
//...
),
//...
2) Maybe consider to try CJuiAutoComplete
http://www.yiiframework.com/doc/api/1.1/CJuiAutoComplete/
It will give you results only on typing and matching your interested data.
Not loading 41k entries and placing them in HTML <option> tags seems to be a very good start... :-)
Only load those you need using AJAX.
Is the state drop-down culling unique states from that table, i.e., you end up with 50-ish results? You might want to construct the query manually and see where the bottleneck is. For complex queries, this is often dramatically faster than using AR, which I'm assuming you are using to create the model. I'm also assuming you are not trying to load 41k records into a drop-down.
We might need a bit more detail about the structure of the table, how you are creating the model, etc.
Using CDbCriteria, I set the "GROUP BY" for the query:
$stateGroupBy = new CDbCriteria; // i got that bitch criteria. bitches love criteria!
$stateGroupBy->group = 'State'; // group by state
echo $form->dropDownList($model, 'State', CHtml::listData(Zipcodes::model()->findAll($stateGroupBy), 'State', 'State'),
array('ajax' =>
array(
'type'=>'POST', //request type
'url'=>CController::createUrl('search/dynamiccities'), #we don't have to use search/, we could just say dynamiccities
'update'=>'#Zipcodes_City',
/*'data'=>'js:jQuery(this).serialize()'*/
),
'empty'=>'-- Choose State --')
);
I flaked out in getting back to this, but this cut down on the load significantly.