I have a form with many textfields ,selects in which one select and one multiselect has same data fetched from database by following code:
//Form1
$form_project=new Project_Form_AddProject();
//Form2
$form_project_type=new Project_Form_ProjectType();
//add values to dropdown companies
$object_company=new Project_Model_DbTable_Company();
$list_companies=$object_company->fetchAll();
foreach ($list_companies as $clist) :
$name = $clist['company_name'];
$dropdown_list[$clist['company_id']] = $clist['company_name'];
endforeach;
foreach ($dropdown_list as $key => $value):
//Line A
$form_project->customer->addMultiOptions($dropdown_list);//customer is select
//Line B
$form_project_type->partner->addMultiOptions($dropdown_list);//partner is multiselect
endforeach;
Here class Project_Model_DbTable_Company maps to a database table named company which contains 328 rows.Now When:
I comment line B everything is going fine but when I uncomment line B error occurs saying as
Maximum execution time of 30 seconds exceeded in ZendFramework-1.11.11\\Zend\Form.php on line 3011
Why is this problem occuring??Is it due to excessive data that I am going to put in two dropdowns on same form?Plz suggest me.Thanks in advance.
The problem is in your second
foreachloop. These linesare adding 328 options 328 times. the
addMultiOptions()method accepts an array and iterates through it. Your code should be changed to:-That should allow your code to run within the
max_execution_timelimit although I still think it’s a bad idea to have 328 options in a drop down. I’m sure a bit of thought on your part would discover a much more elegant and user friendly alternative.Also try changing your foreach blocks to look like this:-
You’ll find your code is much more readable.