0

我的任务是使用 codeigniter 和 json 从数据库创建组织结构。我受到了约束。脚本不工作。

有什么创建它的建议吗?

这是我的数据库(组织):

- table_org
id    urutan     name       title
1        1       aaaa      Head of Logistic
2        2      bbbbbb     Division Logistic
3        3      ccccccc    Staff/Employees, etc...

View :

<body>    
    <div id="people"></div>
    <script type="text/ecmascript">
	 
		var readUrl = "http://localhost/Codeg/struktur_org/";
	 
		$.getJSON(readUrl, function(people) {		
			$('#people').getOrgChart({
				theme: "helen",
				primaryColumns: ["name", "title"],
				imageColumn: "image",
				linkType: "M",
				editable: false,
				dataSource: people 
			});
		});
    </script>	
</body>

Controller :

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
 //we need to call PHP's session object to access it through CI

class Struktur_org extends CI_Controller {

	function __construct()
	{
		parent::__construct();
		$this->load->model('struktur_model');
	}
	
	public function index()//may be index() or something else.Rename this funciton name as yours
	{
		echo json_encode( $this->struktur_model->getMember() );
		$this->load->view('struktur_org');
	}

}

Model :

<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Struktur_model extends CI_Model {

	function __construct()
    {
		parent::__construct();
	}
	
	function getMember(){
		
        $query = $this->db->get('org');
        return $query;
    }
}

4

1 回答 1

0

你的第二列应该是父母 ID。这是一个例子

- table_org
id    urutan     name       title
1        null       aaaa      Head of Logistic
2        1      bbbbbb     Division Logistic
3        1      ccccccc    Staff/Employees, etc...

于 2016-09-03T21:25:54.383 回答