因为我改变了代码
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 :(得分: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");