저는 PyroCMS에서 페이지 관리자 용으로이 작업을 수행했습니다. 쉬운 작업.
각 페이지는 다음 페이지 슬러그의 각을 통해 루프와 아이를 조인 올바른 페이지를 읽고, 자신의 슬러그 및 PARENT_ID 있습니다. 얼마나 많은 아이들이 있는지를 안다. 그래서 5 명의 아이들이 있다면 그것은 5 번째 자기 결합 테이블을 선택한다.
public function get_by_path($segments = array())
{
// If the URI has been passed as a string, explode to create an array of segments
if(is_string($segments))
{
$segments = explode('/', $segments);
}
// Work out how many segments there are
$total_segments = count($segments);
// Which is the target alias (the final page in the tree)
$target_alias = 'p'.$total_segments;
// Start Query, Select (*) from Target Alias, from Pages
$this->db->select($target_alias.'.*');
$this->db->from('pages p1');
// Loop thorugh each Slug
$level = 1;
foreach($segments as $segment)
{
// Current is the current page, child is the next page to join on.
$current_alias = 'p'.$level;
$child_alias = 'p'.($level - 1);
// We dont want to join the first page again
if($level != 1)
{
$this->db->join('pages '.$current_alias, $current_alias.'.parent_id = '.$child_alias.'.id');
}
// Add slug to where clause to keep us on the right tree
$this->db->where($current_alias . '.slug', $segment);
// Increment
++$level;
}
// Can only be one result
$this->db->limit(1);
return $this->db->get()->row();
}
그것은 조금 견과류입니다 그러나 그것은 완벽하게 작동합니다 : 여기
는 코드의 예입니다. 이것은 PyroCMS가 ID와 페이지 URI가 일치하는 룩업 테이블을 유지하기 때문에 실제로 느릴 수 있습니다.
현재 전체 모델을 볼 수 있습니다
http://github.com/philsturgeon/pyrocms/blob/master/application/modules/core/pages/models/pages_m.php
추가 정보가 필요합니다. 이걸 eshop으로 원합니 까? CMS? 또는 순수 컨트롤러? –
내가 기사 시스템을 원한다고 가정 해 봅시다. – kmunky