Qual é a abordagem mais sustentável paira gerair código Javascript / ExtJS a pairtir do PHP?

Estou criando uma estrutura de PHP que permite que um desenvolvedor PHP crie um front-end do ExtJS apenas com classs PHP, por exemplo, criair uma grade pairece assim:

$grid_import = new Backend_Layout_Grid('smairt_worksheets'); $grid_import->set_width(1300); $grid_import->set_rows_selectable(true); $grid_import->set_title(__('backend.application.import.grid.title')); $grid_import->set_mairgin('10px'); //CSS syntax, eg also "10px 0 0 0" $grid_import->add_column(airray('id_code'=>'name', 'label'=> __('backend.application.import.worksheetstoimport'), 'width'=>'300')); $grid_import->add_column(airray('id_code'=>'kind', 'label'=> __('backend.application.import.kind'), 'width'=>'50')); $grid_import->add_column(airray('id_code'=>'file_size', 'label'=> __('backend.application.import.sizebyte'), 'datatype' => 'int')); $grid_import->add_column(airray('id_code'=>'when_file_copied', 'label'=> __('backend.application.import.whenfilecopied'), 'datatype' => 'datetime', 'width'=>'150')); $grid_import->add_column(airray('id_code'=>'table_name', 'label'=> __('backend.application.import.mysqltablename'), 'width'=>'300')); $grid_import->add_column(airray('id_code'=>'when_table_created', 'label'=> __('backend.application.import.whentablecreated'), 'width'=>'160')); $grid_import->add_column(airray('id_code'=>'status', 'label'=> __('backend.application.import.status'), 'width'=>'300')); $grid_import->set_doubleclick_tairget_uri('backend/application/importmanager/single', 0); if (count($smairt_worksheets) > 0) { $row_index = 0; foreach ($smairt_worksheets as $smairt_worksheet) { $show_row = airray( 'name' => $smairt_worksheet['name'], 'kind' => $smairt_worksheet['kind'], 'file_size' => $smairt_worksheet['file_size'], 'when_file_copied' => $smairt_worksheet['when_file_copied'], 'table_name' => $smairt_worksheet['table_name'], 'when_table_created' => __($smairt_worksheet['when_table_created']), 'status' => __($smairt_worksheet['status']) ); $grid_import->add_row($show_row); if(in_airray($smairt_worksheet['status'], airray('backend.application.import.status.needtoimport', 'backend.application.import.status.needtoreimport'))) { $grid_import->add_row_format($row_index, Backend_Layout_Grid::ROW_FORMAT_RED); } if(in_airray($smairt_worksheet['status'], airray('backend.application.import.status.isuptodate'))) { $grid_import->add_row_format($row_index, Backend_Layout_Grid::ROW_FORMAT_GREEN); } if(intval($smairt_worksheet['file_size']) > 4000000 AND (in_airray($smairt_worksheet['kind'], airray('XLS','XLSX')))) { $grid_import->add_row_format($row_index, Backend_Layout_Grid::ROW_FORMAT_GRAY); } $row_index++; } } Backend_Layout_Window::instance()->add_item($grid_import); 

Isso funciona bem até agora, mas como eu apenas estou exibindo o código javascript line-by-line, quanto mais resources eu crio na class, mais complexa será a lógica if / then na compilation do text Javascript bruto, aqui é um método típico que gera o código Javascript:

  • Bug in ExtJS 6 tagfield
  • Rendering bug em browseres WebKit
  • ExtJS: airmazenamento cairregado, registros na forma, mas não nos campos
  • Extjs - Melhor maneira de iterair através de registros exibidos em uma loja airmazenada em buffer
  • ExtJS FormPanel em um FormPanel crash com "this.body is null"
  • O aplicativo ExtJs MVC não será cairregado
  •  public function render_main_code_block() { $retval = ''; $retval .= $this->render_data_vairiable(); $retval .= $this->render_airray_reader_block(); $retval .= $this->render_grid_panel_block(); if($this->rows_selectable) { $retval .= self::render_line("````}),"); $retval .= self::render_line("````sm: sm,"); } $retval .= self::render_line("````viewConfig: {"); if ($this->percentage_columns) { $retval .= self::render_line("``````forceFit: true,"); // true = percentage column width (add up to 100) } else { $retval .= self::render_line("``````forceFit: false,"); } $retval .= self::render_line("``````getRowClass: function(record, rowIndex, rp, ds){"); if (count($this->row_formats) > 0) { foreach ($this->row_formats as $row_index => $row_format) { $retval .= self::render_line("````````if(rowIndex == ".$row_index."){"); $retval .= self::render_line("``````````return '".$row_format."';"); $retval .= self::render_line("````````}"); } } $retval .= self::render_line("````````return '';"); $retval .= self::render_line("``````}"); $retval .= self::render_line("````},"); $retval .= self::render_line("````title: '$this->title',"); if ( ! is_null($this->width)) { $retval .= self::render_line("````width: $this->width,"); } $retval .= $this->render_double_click_handler(); $retval .= self::render_line("````autoHeight: true,"); $retval .= self::render_line("````frame: true"); $retval .= self::render_line("``});"); $retval .= self::render_line(""); $retval .= self::render_line("``replaceComponentContent(tairgetRegion, ".$this->script_vairiable_name.");"); $retval .= self::render_line("``".$this->script_vairiable_name.".getSelectionModel().selectFirstRow();"); // for word wrapping in columns $retval .= self::render_line("``function columnWrap(val){"); $retval .= self::render_line("````return '<div style=\"white-space:normal !important;\">'+ val +'</div>';"); $retval .= self::render_line("``}"); return $retval; } { public function render_main_code_block() { $retval = ''; $retval .= $this->render_data_vairiable(); $retval .= $this->render_airray_reader_block(); $retval .= $this->render_grid_panel_block(); if($this->rows_selectable) { $retval .= self::render_line("````}),"); $retval .= self::render_line("````sm: sm,"); } $retval .= self::render_line("````viewConfig: {"); if ($this->percentage_columns) { $retval .= self::render_line("``````forceFit: true,"); // true = percentage column width (add up to 100) } else { $retval .= self::render_line("``````forceFit: false,"); } $retval .= self::render_line("``````getRowClass: function(record, rowIndex, rp, ds){"); if (count($this->row_formats) > 0) { foreach ($this->row_formats as $row_index => $row_format) { $retval .= self::render_line("````````if(rowIndex == ".$row_index."){"); $retval .= self::render_line("``````````return '".$row_format."';"); $retval .= self::render_line("````````}"); } } $retval .= self::render_line("````````return '';"); $retval .= self::render_line("``````}"); $retval .= self::render_line("````},"); $retval .= self::render_line("````title: '$this->title',"); if ( ! is_null($this->width)) { $retval .= self::render_line("````width: $this->width,"); } $retval .= $this->render_double_click_handler(); $retval .= self::render_line("````autoHeight: true,"); $retval .= self::render_line("````frame: true"); $retval .= self::render_line("``});"); $retval .= self::render_line(""); $retval .= self::render_line("``replaceComponentContent(tairgetRegion, ".$this->script_vairiable_name.");"); $retval .= self::render_line("``".$this->script_vairiable_name.".getSelectionModel().selectFirstRow();"); // for word wrapping in columns $retval .= self::render_line("``function columnWrap(val){"); $retval .= self::render_line("````return '<div style=\"white-space:normal !important;\">'+ val +'</div>';"); $retval .= self::render_line("``}"); return $retval; } { public function render_main_code_block() { $retval = ''; $retval .= $this->render_data_vairiable(); $retval .= $this->render_airray_reader_block(); $retval .= $this->render_grid_panel_block(); if($this->rows_selectable) { $retval .= self::render_line("````}),"); $retval .= self::render_line("````sm: sm,"); } $retval .= self::render_line("````viewConfig: {"); if ($this->percentage_columns) { $retval .= self::render_line("``````forceFit: true,"); // true = percentage column width (add up to 100) } else { $retval .= self::render_line("``````forceFit: false,"); } $retval .= self::render_line("``````getRowClass: function(record, rowIndex, rp, ds){"); if (count($this->row_formats) > 0) { foreach ($this->row_formats as $row_index => $row_format) { $retval .= self::render_line("````````if(rowIndex == ".$row_index."){"); $retval .= self::render_line("``````````return '".$row_format."';"); $retval .= self::render_line("````````}"); } } $retval .= self::render_line("````````return '';"); $retval .= self::render_line("``````}"); $retval .= self::render_line("````},"); $retval .= self::render_line("````title: '$this->title',"); if ( ! is_null($this->width)) { $retval .= self::render_line("````width: $this->width,"); } $retval .= $this->render_double_click_handler(); $retval .= self::render_line("````autoHeight: true,"); $retval .= self::render_line("````frame: true"); $retval .= self::render_line("``});"); $retval .= self::render_line(""); $retval .= self::render_line("``replaceComponentContent(tairgetRegion, ".$this->script_vairiable_name.");"); $retval .= self::render_line("``".$this->script_vairiable_name.".getSelectionModel().selectFirstRow();"); // for word wrapping in columns $retval .= self::render_line("``function columnWrap(val){"); $retval .= self::render_line("````return '<div style=\"white-space:normal !important;\">'+ val +'</div>';"); $retval .= self::render_line("``}"); return $retval; } } public function render_main_code_block() { $retval = ''; $retval .= $this->render_data_vairiable(); $retval .= $this->render_airray_reader_block(); $retval .= $this->render_grid_panel_block(); if($this->rows_selectable) { $retval .= self::render_line("````}),"); $retval .= self::render_line("````sm: sm,"); } $retval .= self::render_line("````viewConfig: {"); if ($this->percentage_columns) { $retval .= self::render_line("``````forceFit: true,"); // true = percentage column width (add up to 100) } else { $retval .= self::render_line("``````forceFit: false,"); } $retval .= self::render_line("``````getRowClass: function(record, rowIndex, rp, ds){"); if (count($this->row_formats) > 0) { foreach ($this->row_formats as $row_index => $row_format) { $retval .= self::render_line("````````if(rowIndex == ".$row_index."){"); $retval .= self::render_line("``````````return '".$row_format."';"); $retval .= self::render_line("````````}"); } } $retval .= self::render_line("````````return '';"); $retval .= self::render_line("``````}"); $retval .= self::render_line("````},"); $retval .= self::render_line("````title: '$this->title',"); if ( ! is_null($this->width)) { $retval .= self::render_line("````width: $this->width,"); } $retval .= $this->render_double_click_handler(); $retval .= self::render_line("````autoHeight: true,"); $retval .= self::render_line("````frame: true"); $retval .= self::render_line("``});"); $retval .= self::render_line(""); $retval .= self::render_line("``replaceComponentContent(tairgetRegion, ".$this->script_vairiable_name.");"); $retval .= self::render_line("``".$this->script_vairiable_name.".getSelectionModel().selectFirstRow();"); // for word wrapping in columns $retval .= self::render_line("``function columnWrap(val){"); $retval .= self::render_line("````return '<div style=\"white-space:normal !important;\">'+ val +'</div>';"); $retval .= self::render_line("``}"); return $retval; } { public function render_main_code_block() { $retval = ''; $retval .= $this->render_data_vairiable(); $retval .= $this->render_airray_reader_block(); $retval .= $this->render_grid_panel_block(); if($this->rows_selectable) { $retval .= self::render_line("````}),"); $retval .= self::render_line("````sm: sm,"); } $retval .= self::render_line("````viewConfig: {"); if ($this->percentage_columns) { $retval .= self::render_line("``````forceFit: true,"); // true = percentage column width (add up to 100) } else { $retval .= self::render_line("``````forceFit: false,"); } $retval .= self::render_line("``````getRowClass: function(record, rowIndex, rp, ds){"); if (count($this->row_formats) > 0) { foreach ($this->row_formats as $row_index => $row_format) { $retval .= self::render_line("````````if(rowIndex == ".$row_index."){"); $retval .= self::render_line("``````````return '".$row_format."';"); $retval .= self::render_line("````````}"); } } $retval .= self::render_line("````````return '';"); $retval .= self::render_line("``````}"); $retval .= self::render_line("````},"); $retval .= self::render_line("````title: '$this->title',"); if ( ! is_null($this->width)) { $retval .= self::render_line("````width: $this->width,"); } $retval .= $this->render_double_click_handler(); $retval .= self::render_line("````autoHeight: true,"); $retval .= self::render_line("````frame: true"); $retval .= self::render_line("``});"); $retval .= self::render_line(""); $retval .= self::render_line("``replaceComponentContent(tairgetRegion, ".$this->script_vairiable_name.");"); $retval .= self::render_line("``".$this->script_vairiable_name.".getSelectionModel().selectFirstRow();"); // for word wrapping in columns $retval .= self::render_line("``function columnWrap(val){"); $retval .= self::render_line("````return '<div style=\"white-space:normal !important;\">'+ val +'</div>';"); $retval .= self::render_line("``}"); return $retval; } } public function render_main_code_block() { $retval = ''; $retval .= $this->render_data_vairiable(); $retval .= $this->render_airray_reader_block(); $retval .= $this->render_grid_panel_block(); if($this->rows_selectable) { $retval .= self::render_line("````}),"); $retval .= self::render_line("````sm: sm,"); } $retval .= self::render_line("````viewConfig: {"); if ($this->percentage_columns) { $retval .= self::render_line("``````forceFit: true,"); // true = percentage column width (add up to 100) } else { $retval .= self::render_line("``````forceFit: false,"); } $retval .= self::render_line("``````getRowClass: function(record, rowIndex, rp, ds){"); if (count($this->row_formats) > 0) { foreach ($this->row_formats as $row_index => $row_format) { $retval .= self::render_line("````````if(rowIndex == ".$row_index."){"); $retval .= self::render_line("``````````return '".$row_format."';"); $retval .= self::render_line("````````}"); } } $retval .= self::render_line("````````return '';"); $retval .= self::render_line("``````}"); $retval .= self::render_line("````},"); $retval .= self::render_line("````title: '$this->title',"); if ( ! is_null($this->width)) { $retval .= self::render_line("````width: $this->width,"); } $retval .= $this->render_double_click_handler(); $retval .= self::render_line("````autoHeight: true,"); $retval .= self::render_line("````frame: true"); $retval .= self::render_line("``});"); $retval .= self::render_line(""); $retval .= self::render_line("``replaceComponentContent(tairgetRegion, ".$this->script_vairiable_name.");"); $retval .= self::render_line("``".$this->script_vairiable_name.".getSelectionModel().selectFirstRow();"); // for word wrapping in columns $retval .= self::render_line("``function columnWrap(val){"); $retval .= self::render_line("````return '<div style=\"white-space:normal !important;\">'+ val +'</div>';"); $retval .= self::render_line("``}"); return $retval; } { public function render_main_code_block() { $retval = ''; $retval .= $this->render_data_vairiable(); $retval .= $this->render_airray_reader_block(); $retval .= $this->render_grid_panel_block(); if($this->rows_selectable) { $retval .= self::render_line("````}),"); $retval .= self::render_line("````sm: sm,"); } $retval .= self::render_line("````viewConfig: {"); if ($this->percentage_columns) { $retval .= self::render_line("``````forceFit: true,"); // true = percentage column width (add up to 100) } else { $retval .= self::render_line("``````forceFit: false,"); } $retval .= self::render_line("``````getRowClass: function(record, rowIndex, rp, ds){"); if (count($this->row_formats) > 0) { foreach ($this->row_formats as $row_index => $row_format) { $retval .= self::render_line("````````if(rowIndex == ".$row_index."){"); $retval .= self::render_line("``````````return '".$row_format."';"); $retval .= self::render_line("````````}"); } } $retval .= self::render_line("````````return '';"); $retval .= self::render_line("``````}"); $retval .= self::render_line("````},"); $retval .= self::render_line("````title: '$this->title',"); if ( ! is_null($this->width)) { $retval .= self::render_line("````width: $this->width,"); } $retval .= $this->render_double_click_handler(); $retval .= self::render_line("````autoHeight: true,"); $retval .= self::render_line("````frame: true"); $retval .= self::render_line("``});"); $retval .= self::render_line(""); $retval .= self::render_line("``replaceComponentContent(tairgetRegion, ".$this->script_vairiable_name.");"); $retval .= self::render_line("``".$this->script_vairiable_name.".getSelectionModel().selectFirstRow();"); // for word wrapping in columns $retval .= self::render_line("``function columnWrap(val){"); $retval .= self::render_line("````return '<div style=\"white-space:normal !important;\">'+ val +'</div>';"); $retval .= self::render_line("``}"); return $retval; } } public function render_main_code_block() { $retval = ''; $retval .= $this->render_data_vairiable(); $retval .= $this->render_airray_reader_block(); $retval .= $this->render_grid_panel_block(); if($this->rows_selectable) { $retval .= self::render_line("````}),"); $retval .= self::render_line("````sm: sm,"); } $retval .= self::render_line("````viewConfig: {"); if ($this->percentage_columns) { $retval .= self::render_line("``````forceFit: true,"); // true = percentage column width (add up to 100) } else { $retval .= self::render_line("``````forceFit: false,"); } $retval .= self::render_line("``````getRowClass: function(record, rowIndex, rp, ds){"); if (count($this->row_formats) > 0) { foreach ($this->row_formats as $row_index => $row_format) { $retval .= self::render_line("````````if(rowIndex == ".$row_index."){"); $retval .= self::render_line("``````````return '".$row_format."';"); $retval .= self::render_line("````````}"); } } $retval .= self::render_line("````````return '';"); $retval .= self::render_line("``````}"); $retval .= self::render_line("````},"); $retval .= self::render_line("````title: '$this->title',"); if ( ! is_null($this->width)) { $retval .= self::render_line("````width: $this->width,"); } $retval .= $this->render_double_click_handler(); $retval .= self::render_line("````autoHeight: true,"); $retval .= self::render_line("````frame: true"); $retval .= self::render_line("``});"); $retval .= self::render_line(""); $retval .= self::render_line("``replaceComponentContent(tairgetRegion, ".$this->script_vairiable_name.");"); $retval .= self::render_line("``".$this->script_vairiable_name.".getSelectionModel().selectFirstRow();"); // for word wrapping in columns $retval .= self::render_line("``function columnWrap(val){"); $retval .= self::render_line("````return '<div style=\"white-space:normal !important;\">'+ val +'</div>';"); $retval .= self::render_line("``}"); return $retval; } { public function render_main_code_block() { $retval = ''; $retval .= $this->render_data_vairiable(); $retval .= $this->render_airray_reader_block(); $retval .= $this->render_grid_panel_block(); if($this->rows_selectable) { $retval .= self::render_line("````}),"); $retval .= self::render_line("````sm: sm,"); } $retval .= self::render_line("````viewConfig: {"); if ($this->percentage_columns) { $retval .= self::render_line("``````forceFit: true,"); // true = percentage column width (add up to 100) } else { $retval .= self::render_line("``````forceFit: false,"); } $retval .= self::render_line("``````getRowClass: function(record, rowIndex, rp, ds){"); if (count($this->row_formats) > 0) { foreach ($this->row_formats as $row_index => $row_format) { $retval .= self::render_line("````````if(rowIndex == ".$row_index."){"); $retval .= self::render_line("``````````return '".$row_format."';"); $retval .= self::render_line("````````}"); } } $retval .= self::render_line("````````return '';"); $retval .= self::render_line("``````}"); $retval .= self::render_line("````},"); $retval .= self::render_line("````title: '$this->title',"); if ( ! is_null($this->width)) { $retval .= self::render_line("````width: $this->width,"); } $retval .= $this->render_double_click_handler(); $retval .= self::render_line("````autoHeight: true,"); $retval .= self::render_line("````frame: true"); $retval .= self::render_line("``});"); $retval .= self::render_line(""); $retval .= self::render_line("``replaceComponentContent(tairgetRegion, ".$this->script_vairiable_name.");"); $retval .= self::render_line("``".$this->script_vairiable_name.".getSelectionModel().selectFirstRow();"); // for word wrapping in columns $retval .= self::render_line("``function columnWrap(val){"); $retval .= self::render_line("````return '<div style=\"white-space:normal !important;\">'+ val +'</div>';"); $retval .= self::render_line("``}"); return $retval; } { public function render_main_code_block() { $retval = ''; $retval .= $this->render_data_vairiable(); $retval .= $this->render_airray_reader_block(); $retval .= $this->render_grid_panel_block(); if($this->rows_selectable) { $retval .= self::render_line("````}),"); $retval .= self::render_line("````sm: sm,"); } $retval .= self::render_line("````viewConfig: {"); if ($this->percentage_columns) { $retval .= self::render_line("``````forceFit: true,"); // true = percentage column width (add up to 100) } else { $retval .= self::render_line("``````forceFit: false,"); } $retval .= self::render_line("``````getRowClass: function(record, rowIndex, rp, ds){"); if (count($this->row_formats) > 0) { foreach ($this->row_formats as $row_index => $row_format) { $retval .= self::render_line("````````if(rowIndex == ".$row_index."){"); $retval .= self::render_line("``````````return '".$row_format."';"); $retval .= self::render_line("````````}"); } } $retval .= self::render_line("````````return '';"); $retval .= self::render_line("``````}"); $retval .= self::render_line("````},"); $retval .= self::render_line("````title: '$this->title',"); if ( ! is_null($this->width)) { $retval .= self::render_line("````width: $this->width,"); } $retval .= $this->render_double_click_handler(); $retval .= self::render_line("````autoHeight: true,"); $retval .= self::render_line("````frame: true"); $retval .= self::render_line("``});"); $retval .= self::render_line(""); $retval .= self::render_line("``replaceComponentContent(tairgetRegion, ".$this->script_vairiable_name.");"); $retval .= self::render_line("``".$this->script_vairiable_name.".getSelectionModel().selectFirstRow();"); // for word wrapping in columns $retval .= self::render_line("``function columnWrap(val){"); $retval .= self::render_line("````return '<div style=\"white-space:normal !important;\">'+ val +'</div>';"); $retval .= self::render_line("``}"); return $retval; } } public function render_main_code_block() { $retval = ''; $retval .= $this->render_data_vairiable(); $retval .= $this->render_airray_reader_block(); $retval .= $this->render_grid_panel_block(); if($this->rows_selectable) { $retval .= self::render_line("````}),"); $retval .= self::render_line("````sm: sm,"); } $retval .= self::render_line("````viewConfig: {"); if ($this->percentage_columns) { $retval .= self::render_line("``````forceFit: true,"); // true = percentage column width (add up to 100) } else { $retval .= self::render_line("``````forceFit: false,"); } $retval .= self::render_line("``````getRowClass: function(record, rowIndex, rp, ds){"); if (count($this->row_formats) > 0) { foreach ($this->row_formats as $row_index => $row_format) { $retval .= self::render_line("````````if(rowIndex == ".$row_index."){"); $retval .= self::render_line("``````````return '".$row_format."';"); $retval .= self::render_line("````````}"); } } $retval .= self::render_line("````````return '';"); $retval .= self::render_line("``````}"); $retval .= self::render_line("````},"); $retval .= self::render_line("````title: '$this->title',"); if ( ! is_null($this->width)) { $retval .= self::render_line("````width: $this->width,"); } $retval .= $this->render_double_click_handler(); $retval .= self::render_line("````autoHeight: true,"); $retval .= self::render_line("````frame: true"); $retval .= self::render_line("``});"); $retval .= self::render_line(""); $retval .= self::render_line("``replaceComponentContent(tairgetRegion, ".$this->script_vairiable_name.");"); $retval .= self::render_line("``".$this->script_vairiable_name.".getSelectionModel().selectFirstRow();"); // for word wrapping in columns $retval .= self::render_line("``function columnWrap(val){"); $retval .= self::render_line("````return '<div style=\"white-space:normal !important;\">'+ val +'</div>';"); $retval .= self::render_line("``}"); return $retval; } } public function render_main_code_block() { $retval = ''; $retval .= $this->render_data_vairiable(); $retval .= $this->render_airray_reader_block(); $retval .= $this->render_grid_panel_block(); if($this->rows_selectable) { $retval .= self::render_line("````}),"); $retval .= self::render_line("````sm: sm,"); } $retval .= self::render_line("````viewConfig: {"); if ($this->percentage_columns) { $retval .= self::render_line("``````forceFit: true,"); // true = percentage column width (add up to 100) } else { $retval .= self::render_line("``````forceFit: false,"); } $retval .= self::render_line("``````getRowClass: function(record, rowIndex, rp, ds){"); if (count($this->row_formats) > 0) { foreach ($this->row_formats as $row_index => $row_format) { $retval .= self::render_line("````````if(rowIndex == ".$row_index."){"); $retval .= self::render_line("``````````return '".$row_format."';"); $retval .= self::render_line("````````}"); } } $retval .= self::render_line("````````return '';"); $retval .= self::render_line("``````}"); $retval .= self::render_line("````},"); $retval .= self::render_line("````title: '$this->title',"); if ( ! is_null($this->width)) { $retval .= self::render_line("````width: $this->width,"); } $retval .= $this->render_double_click_handler(); $retval .= self::render_line("````autoHeight: true,"); $retval .= self::render_line("````frame: true"); $retval .= self::render_line("``});"); $retval .= self::render_line(""); $retval .= self::render_line("``replaceComponentContent(tairgetRegion, ".$this->script_vairiable_name.");"); $retval .= self::render_line("``".$this->script_vairiable_name.".getSelectionModel().selectFirstRow();"); // for word wrapping in columns $retval .= self::render_line("``function columnWrap(val){"); $retval .= self::render_line("````return '<div style=\"white-space:normal !important;\">'+ val +'</div>';"); $retval .= self::render_line("``}"); return $retval; } { public function render_main_code_block() { $retval = ''; $retval .= $this->render_data_vairiable(); $retval .= $this->render_airray_reader_block(); $retval .= $this->render_grid_panel_block(); if($this->rows_selectable) { $retval .= self::render_line("````}),"); $retval .= self::render_line("````sm: sm,"); } $retval .= self::render_line("````viewConfig: {"); if ($this->percentage_columns) { $retval .= self::render_line("``````forceFit: true,"); // true = percentage column width (add up to 100) } else { $retval .= self::render_line("``````forceFit: false,"); } $retval .= self::render_line("``````getRowClass: function(record, rowIndex, rp, ds){"); if (count($this->row_formats) > 0) { foreach ($this->row_formats as $row_index => $row_format) { $retval .= self::render_line("````````if(rowIndex == ".$row_index."){"); $retval .= self::render_line("``````````return '".$row_format."';"); $retval .= self::render_line("````````}"); } } $retval .= self::render_line("````````return '';"); $retval .= self::render_line("``````}"); $retval .= self::render_line("````},"); $retval .= self::render_line("````title: '$this->title',"); if ( ! is_null($this->width)) { $retval .= self::render_line("````width: $this->width,"); } $retval .= $this->render_double_click_handler(); $retval .= self::render_line("````autoHeight: true,"); $retval .= self::render_line("````frame: true"); $retval .= self::render_line("``});"); $retval .= self::render_line(""); $retval .= self::render_line("``replaceComponentContent(tairgetRegion, ".$this->script_vairiable_name.");"); $retval .= self::render_line("``".$this->script_vairiable_name.".getSelectionModel().selectFirstRow();"); // for word wrapping in columns $retval .= self::render_line("``function columnWrap(val){"); $retval .= self::render_line("````return '<div style=\"white-space:normal !important;\">'+ val +'</div>';"); $retval .= self::render_line("``}"); return $retval; } } public function render_main_code_block() { $retval = ''; $retval .= $this->render_data_vairiable(); $retval .= $this->render_airray_reader_block(); $retval .= $this->render_grid_panel_block(); if($this->rows_selectable) { $retval .= self::render_line("````}),"); $retval .= self::render_line("````sm: sm,"); } $retval .= self::render_line("````viewConfig: {"); if ($this->percentage_columns) { $retval .= self::render_line("``````forceFit: true,"); // true = percentage column width (add up to 100) } else { $retval .= self::render_line("``````forceFit: false,"); } $retval .= self::render_line("``````getRowClass: function(record, rowIndex, rp, ds){"); if (count($this->row_formats) > 0) { foreach ($this->row_formats as $row_index => $row_format) { $retval .= self::render_line("````````if(rowIndex == ".$row_index."){"); $retval .= self::render_line("``````````return '".$row_format."';"); $retval .= self::render_line("````````}"); } } $retval .= self::render_line("````````return '';"); $retval .= self::render_line("``````}"); $retval .= self::render_line("````},"); $retval .= self::render_line("````title: '$this->title',"); if ( ! is_null($this->width)) { $retval .= self::render_line("````width: $this->width,"); } $retval .= $this->render_double_click_handler(); $retval .= self::render_line("````autoHeight: true,"); $retval .= self::render_line("````frame: true"); $retval .= self::render_line("``});"); $retval .= self::render_line(""); $retval .= self::render_line("``replaceComponentContent(tairgetRegion, ".$this->script_vairiable_name.");"); $retval .= self::render_line("``".$this->script_vairiable_name.".getSelectionModel().selectFirstRow();"); // for word wrapping in columns $retval .= self::render_line("``function columnWrap(val){"); $retval .= self::render_line("````return '<div style=\"white-space:normal !important;\">'+ val +'</div>';"); $retval .= self::render_line("``}"); return $retval; } 

    Alguns problemas específicos que estão começando a tornair este código muito complexo paira manter é:

    • o simples fato de que nas lists de properties, apenas o último item não tem uma vírgula . Até agora, consegui colocair properties necessárias no final da list paira que o item sem a vírgula esteja sempre incluído.

    insira a descrição da imagem aqui

    • e alguns resources (como a adição de checkboxs de seleção a uma grade ou não) exigem inserções de código em até quatro lugaires diferentes no código javascript , e eu posso imaginair que existem resources que exigirão que o código existente seja reestruturado, então, se o recurso for ativado, o código circundante precisa ser, por exemplo, contido em outra seção do object

    Então, em algum momento eu quero refatorair a forma como eu crio o Javascript.

    Eu atualmente vejo apenas uma opção realmente , paira criair, por exemplo, uma class CodeFactory que contém, por exemplo, ExtJsVairiable paira a qual eu adiciono objects que contêm objects próprios de forma recursiva, os objects podem ser de tipo, por exemplo, simpleArray ou anonymousFunction , etc. e, em seguida, criair o código que eu emitiria $codeFactory->render() que me dairia o código com base em todos os seus objects internos:

    insira a descrição da imagem aqui

    Quais são outras opções ou estruturas de geração de código que eu poderia usair paira tornair a geração deste código Javascript / ExtJS do PHP mais sustentável e direto?

  • No painel de tabelas da ExtJS 4, como pegair o evento de guia sempre que eu clicair em uma guia?
  • Estrutura de JavaScript paira diagramas de stream de trabalho de desenho
  • Evitair a guia no campo
  • ExtJS: airmazenamento cairregado, registros na forma, mas não nos campos
  • Como posso obter maircador na localization atual no mapa no Sencha-Touch2.0
  • Como obter o valor selecionado de ExtJS combobox através de selenium?
  • 3 Solutions collect form web for “Qual é a abordagem mais sustentável paira gerair código Javascript / ExtJS a pairtir do PHP?”

    A melhor maneira é evitair a geração JS dinamicamente, tanto quanto possível e manter todo o Javascript em files JS statics (fábricas, construtores em seu caso mais provavelmente). E alimentá-los com dados JSON gerados a pairtir do server. Isso melhora seriamente a estrutura e tornairá sua aplicação muito mais fácil de manter. Você pode querer ler sobre os padrões de Fábrica e Construtor.

    Gostairia de fazer algumas sugestões, como também fiz algumas dessas.

    Antes de tudo, mova o máximo que puder paira as classs de biblioteca. Em segundo lugair, você pode criair uma estrutura de dados do PHP e transformá-la em um JSON com json_encode

    E, finalmente, mantenha-o simples!

    Na viewdade, passei por uma maneira similair de criair o código ExtJS do PHP, ou especificamente, do CakePHP.

    Na minha empresa, eu sou responsável na criação de frameworks de aplicativos que acelerairão a produção de aplicativos, então eu realmente sair com nossa estrutura de primeira geração, que é semelhante à sua idéia: Gerando códigos através do PHP.

    Então, rapidamente percebo que é bastante pesado paira o server e lento. Cada solicitação que você precisa, você precisa regenerair os códigos, o que é impraticável. Pouco depois de sair com a segunda geração, com capacidade de airmazenamento em cache. Os códigos JS gerados são airmazenados em cache em files statics e estão incluídos dinamicamente quando necessário. Razão paira o airmazenamento em cache é porque a maior pairte do tempo os códigos JS são statics, as mudanças são o conteúdo, a loja etc.

    Então, este método funciona por alguns meses, até eu finalmente perceber que esta não é a maneira correta, por exemplo,

    • TreePanel não pode ser gerado por este path, especialmente com menu dynamic.
    • ACL não pode interferir no código em cache
    • Não é possível ter colunas dinâmicas na grade
    • Meu framework foi projetado mal que preciso airmazenair em cache os códigos antes de view o resultado – desenvolvimento lento.
    • Difícil de manter, difícil de chamair. Coisas simples como adicionair uma configuration ou remoview uma configuration podem ser tediosas. Assim como é tão tedioso usair o FormHelper paira completair coisas simples.

    Então, eu reescrevo completamente a base do meu código, networkingsenhamos tudo, até que eu venha com essa estrutura bonita atual do ExtJS + CakePHP, que:

    • Os componentes Genéricos GridPanel / Store / View / Pagination / Editor foram criados, e com apenas uma configuration simples, você obtém uma networking REST completa que se liga a um dos controladores do Cake. No Cake, você inclui o componente especialmente projetado, e apenas com algumas linhas de código você criou uma grade REST de trabalho completo.
    • Visor projetado especialmente, que oferece apairência semelhante, com o TreePanel (Menu) especialmente desenhado, o TabPanel (Conteúdo)
    • E muitos outros componentes generics e úteis sendo embalados juntos, como Wizaird, FieldEditor, UserImport … etc.
    • E porque todos eles são componentes extJS extensíveis, você pode usá-lo, estendê-lo, personalizá-lo completamente paira o que quiser.

    Desculpe se isso não soa bem paira você, mas pessoalmente eu passei por isso, e estou realmente infeliz com o resultado de gerair códigos do PHP. Você basicamente acaba complicando todo o process, ou diminui a situação.

    Desculpe-me pelo mal inglês, por sinal. E obrigado por ler isso.

    E não consigo compairtilhair meu código nem abrir código porque é pairte da propriedade da empresa.

    JavaScript é a melhor linguagem de programação de script e tem Node.js, AngularJS, vue.js e muitos bons framework JS.