2013-07-08 4 views
0

PHP에서 몇 가지 지식이 누락되어 제대로 작동하지 않는 것 같습니다. CodeIgniter가 새로운 값을 구성 파일의 배열에 넣습니다.

내가이 값으로 application/config/cfg.backend.php 가지고있다

$config['head_meta']   = array(
    'stylesheets'    => array(
     'template.css' 
    ), 
    'scripts'     => array(
     'plugins/jquery-2.0.3.min.js', 
     'plugins/bootstrap.min.js' 
    ), 
    'end_scripts'    => array(
     'plugins/jquery-ui.js', 
     'plugins/jquery.dataTables.min.js', 
     'template.js' 
    ) 
); 

내가 필요한 모든 스크립트와 CSS 파일을로드를, 그래서 이러한 배열의 일부를 확장해야합니다 때마다, 나는 단지 내가 같은 array_push() 기능을 사용합니다 내 application/controllers/backend/Categories.php에서 한 :

class Categories extends Backend_Controller{ 

    function __construct(){ 

     parent::__construct(); 

     // Load dependencies 
     $head_meta = config_item('head_meta'); 
     array_push($head_meta['end_scripts'], 'plugins/redactor.min.js', 'categories.js'); 
     array_push($head_meta['stylesheets'], 'redactor.css'); 
     var_dump($head_meta['end_scripts']); 
    } 

    // THE REST OF THE CLASS ... 
} 

는 그래서 var_dump($head_meta['end_scripts'])을 수행하여, 나는 array_push() 자신의 일을했다하지만 내 스크립트가로드되지 않았 음을 확인하고, I'am 여기 stucked 이유를 모르겠어요.

array (size=5) 
    0 => string 'plugins/jquery-ui.js' (length=20) 
    1 => string 'plugins/jquery.dataTables.min.js' (length=32) 
    2 => string 'template.js' (length=11) 
    3 => string 'plugins/redactor.min.js' (length=23) 
    4 => string 'categories.js' (length=13) 

내가 뭘 잘못했는지 제안 해주세요.

==== 업데이트] ====

나는 내가 foreach()end_scripts을로드 할 경우 페이지 하단에 applications/views/backend/templates/template.php에있는 주요 템플릿 파일이 있습니다

<?php foreach($this->config->item('end_scripts', 'head_meta') as $end_scripts):?> 
    <script src="<?php echo base_url();?>assets/js/<?php echo $end_scripts;?>" type="text/javascript"></script> 
<?php endforeach;?> 

특정보기를 메인 templates/template.php에로드하려면 다음과 같이하십시오 :

// Insert catched data into the component view of main template 
    $data['component'] = $this->load->view('backend/category_list', $componentData, TRUE); 

    // Load a component view into the main template 
    $this->load->view('backend/templates/template', $data); 
+0

실제로보기에 스크립트 태그를 인쇄하고 있습니까? –

+0

렌더링 된 소스 코드를 브라우저 또는 방화범이 적용된 파일에서 볼 수 있습니까? 당신의 길은 맞습니까? – vishal

+0

@BadWolf - 질문을 업데이트했습니다. pls는 업데이트 된 섹션을 참조합니다. – aspirinemaga

답변

1

Codeigniter Config 클래스는 구성 변수를 클래스 내에로드하여 $this->config->set_item()을 호출하지 않고 불변으로 만듭니다. 컨트롤러에서 config 클래스의 배열에 변수를 추가하려면 배열을 수정 한 다음 프로그램의 다른 위치에서 액세스하기 전에 변수를 다시 config 클래스로 설정해야합니다.

class Categories extends Backend_Controller{ 

    function __construct(){ 

     parent::__construct(); 

     // Load dependencies 
     $head_meta = config_item('head_meta'); 
     array_push($head_meta['end_scripts'], 'plugins/redactor.min.js', 'categories.js'); 
     array_push($head_meta['stylesheets'], 'redactor.css'); 
     $this->config->set_item('head_meta', $head_meta); 
     var_dump($this->config->get_item('head_meta')); 
    } 

    // THE REST OF THE CLASS ... 
} 
+0

오, 지금은, 물건을 명확히 해 주셔서 고맙습니다. 나는 클래스 바가 오버라이드를 위해 잠겨 있다는 것을 몰랐습니다. – aspirinemaga

관련 문제