Doctrine inheritance. Is there an easy way to get all child classes/tables for using them in a select field in symfony forms?

StackOverflow https://stackoverflow.com/questions/2346742

문제

I just started to use symfony 1.4 and Doctrine. (Used 1.0 - 1.2 + Propel a lot before).

I thought to give Doctrine a try, because of the fast and huge Development process in the past.

Thanks to jwage ;-)

Im using Table Inheritance. This is a small portion of my schema.yml:

Articles:
  columns:
id: 
  type: integer(4) 
  primary: true 
  notnull: true 
  autoincrement: true 
marken_id: 
  type: integer(4) 
  notnull: false 
user_id: 
  type: integer(4) 
  notnull: false 
address_id: 
  type: integer(4) 
  notnull: false 

...

Vehicles: 

 inheritance: 
   extends: Articles 
   type: concrete 

Rennfahrzeuge: 
 columns: 
  stvo: 
    type: boolean 
    notnull: false 
    default: false 
 inheritance: 
  extends: Vehicles 
  type: concrete 


Tourenwagen: 
  inheritance: 
   extends: Rennfahrzeuge 
   type: column_aggregation 
   keyField: type 
   keyValue: 1 

...

 Sonstige:
   inheritance: 
   extends: Rennfahrzeuge 
   type: column_aggregation 
   keyField: type 
   keyValue: 6 

 Karts: 
   inheritance: 
   extends: Vehicles 
   type: concrete 
 TonyKart: 
   inheritance: 
   extends: Karts 
   type: column_aggregation 
   keyField: type 
   keyValue: 1 

...

   Sonstige:
   inheritance: 
    extends: Karts 
    type: column_aggregation 
    keyField: type 
    keyValue: 9 

Im now thinking of using a simple way to create a the right form.

The user should have to select fields at the top of the form (like you can see here : http://msm-esv.dyndns.org/frontend_dev.php/fahrzeuge/insert )

You should choose the "parent class" like Rennfahrzeuge or Karts and so on.

After that the user should choose the child class like Tourenwagen or Sonstige.

Then the page should reload and display the right form.

Is there any function in Doctrine to get the inheritated/child classes for displaying them in the second select field?

(e.g. Rennfahrzeuge has Tourenwagen,..,..., Sonstige and Karts has TonyKart,...,...,Sonstige)

After that i could create dynamically the assigned form class like:

$chooseMode      = $request->getParameter('chooseMode').'Form'; 
$modeFormClass   = new $chooseMode(); 

or i have thought about just setting the right model in the parent form class.

What are your thoughts? I would really appreciate any suggestions and help :-)

Thanks a lot,

Marco

도움이 되었습니까?

해결책

아래 코드를 사용하여 항목 제목이있는 툴팁을 표시하고 있습니다.

$(document).ready(function() {
    ExecuteOrDelayUntilScriptLoaded(tooltipDisplay, "sp.js");
});

var itemID = "";
var title = "";
var offset = null;

function tooltipDisplay() {
    $("table.ms-listviewtable tr.ms-itmhover").hover(function(e){       
        var iids = $(this).attr('iid').split(',');
        itemID = iids[1];
        offset = $(this).offset();              
        showTooltip();
    },
    function(){  
        $("#tblToolTip").remove();
    });
}

function showTooltip() {    
    var clientContext = new SP.ClientContext.get_current(); 
    if (clientContext != undefined && clientContext != null) {
        var list = clientContext.get_web().get_lists().getByTitle("MyList");
        this.listItem = list.getItemById(itemID);
        clientContext.load(this.listItem, 'Title');
        clientContext.executeQueryAsync(Function.createDelegate(this, this.Success), 
                                        Function.createDelegate(this, this.Failed));
    }   
}

function Success() {
    title = listItem.get_item('Title');
    if (title != undefined && title != null && title != "") {
        displayTooltip();
    }   
}

function Failed(sender, args) {
    alert('Getting data failed. </br>Message: ' + args.get_message());
}

function displayTooltip() {
    var tempHtml = "<table id='tblToolTip'><tr>";   
    tempHtml += "<td id='tdToolTip' class='toolTipDisplay'>";
    tempHtml += "Title : " + title; 
    tempHtml += "</td></tr></table>";      
    $("body").append(tempHtml);     
    var obj = $("#tblToolTip");             
    obj.css({"position":"absolute", "top":(offset.top + 20) + "px", "left":offset.left + 20}).fadeIn("slow");
}
.

여기에 사용되는 toolTipDisplay가 툴팁의 배경색을 정의합니다.클래스가 포함 된 CSS 파일은 코드에서 참조해야합니다. 또는 배경색이 인라인으로 선언 된 색상입니다.

다른 팁

If you need to find the subclasses of a Doctrine Record you could use
$yourSuperObject->getTable()->getOption('subclasses') or
Doctrine::getTable('SuperClass')->getOption('subclasses');

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top