2017-03-07 31 views
0

因爲我改變了代碼任務詳細信息被保存到數據庫中,但鏈接任務之間的細節沒有被保存

FROM(注意,這部分代碼是節省了任務,並鏈接詳細信息):

$res=mysql_connect("localhost","root",""); 
mysql_select_db("gantt"); 
$gantt = new JSONGanttConnector($res); 
$gantt->render_links("gantt_links","id","source,target,type"); 
$gantt->render_table("gantt_tasks","id","start_date,duration,text,progress,sortorder,parent"); 

TO:

$connector = new JSONGanttConnector($res); 
function default_values($action){ 
global $user_id; 
$action->add_field("userId", $user_id);    
} 
$connector->event->attach("beforeProcessing","default_values"); 
$connector->render_sql("select * from gantt_tasks where userId = ".$user_id,"id","start_date,duration,text,progress,sortorder,parent"); 
$connector->render_sql("select * from gantt_links where userId = ".$user_id,"id","source,target,type"); 
$connector ->render_links("gantt_links","id","source,target,type,userId"); 
$connector->render_table("gantt_tasks","id","start_date,duration,text,progress,sortorder,parent,userId"); 

它不僅節省了任務的詳細信息,但任務之間不連接的細節。我不明白爲什麼?就好像它忽略了代碼中的第二個render_mysql。

回答

0

我不認爲這是一個有效的建材

$connector->render_sql("select * from gantt_tasks where userId = ".$user_id,"id","start_date,duration,text,progress,sortorder,parent"); 
$connector->render_sql("select * from gantt_links where userId = ".$user_id,"id","source,target,type"); 
$connector ->render_links("gantt_links","id","source,target,type,userId"); 
$connector->render_table("gantt_tasks","id","start_date,duration,text,progress,sortorder,parent,userId"); 

render_table/render_sql預計將每個連接器只有一次,所以我不知道你的代碼是如何工作的吧。

由於您需要將配置應用於鏈接,因此可以顯式初始化鏈接連接器。 此代碼

$dbtype = "MySQL"; 

$gantt = new JSONGanttConnector($res, $dbtype); 

$gantt->render_links("gantt_links", "id", "source,target,type"); 
$gantt->render_table("gantt_tasks","id","start_date,duration,text,progress,parent",""); 

是相同的:

$gantt = new JSONGanttConnector($res, $dbtype); 

$links = new JSONGanttLinksConnector($res, $dbtype); 
$links->render_table("gantt_links", "id", "source,target,type"); 
$gantt->set_options("links", $links); 

$gantt->render_table("gantt_tasks","id","start_date,duration,text,progress,parent",""); 

至於由USER_ID過濾,我覺得以下應該做的:

function default_values($action){ 
    global $user_id; 
    $action->add_field("userId", $user_id); 
} 

$gantt = new JSONGanttConnector($res); 

$links = new JSONGanttLinksConnector($res); 

$links->filter("userId", $user_id); 
$links->event->attach("beforeProcessing","default_values"); 
$links->render_table("gantt_links", "id", "source,target,type,userId"); 
$gantt->set_options("links", $links); 

$gantt->filter("userId", $user_id); 
$gantt->event->attach("beforeProcessing","default_values"); 
$gantt->render_table("gantt_tasks","id","start_date,duration,text,progress,parent,userId"); 
+0

$鏈接 - >過濾器( 「用戶id」 $ USER_ID); $ links-> event-> attach(「beforeProcessing」,「default_values」); $ gantt-> render_links(「gantt_links」,「id」,「source,target,type,userId」); $ gantt-> filter(「userId」,$ user_id); $ gantt-> event-> attach(「beforeProcessing」,「default_values」); $ gantt-> render_sql(「select * from gantt_tasks where userId =」。$ user_id,「id」,「start_date,duration,text,progress,sortorder,parent」); $ gantt-> render_table(「gantt_tasks」,「id」,「start_date,duration,text,progress,parent,userId」); –

+0

這段代碼可以工作,它可以保存表中的任務和鏈接細節。但是這次問題是,在gantt_links表中,只有userId沒有被保存:/。我不明白爲什麼userId沒有被保存..你能幫我解決它嗎? –

+0

它得到解決,非常感謝你。 –

相關問題