2011-08-25 8 views

답변

0

이것은 실제로 매우 복잡한 과정입니다.

MojoMotor에는 설치 스크립트가있어서 application/config/database.php을 추가하는 것은 불가능하지 않습니다.

MM에 대한 라이센스 계약으로 인해 실제 설치 스크립트를 게시 할 수 없지만 작동하는 스크립트를 만들 수 있어야합니다.

그렇지 않으면이 같은 상상 :

// Data from user input 
    $db_config['hostname'] = $this->input->post('db_host'); 
    $db_config['username'] = $this->input->post('db_user'); 
    $db_config['password'] = $this->input->post('db_password'); 
    $db_config['database'] = $this->input->post('db_name'); 
    $db_config['dbdriver'] = $this->db_driver; 
    $db_config['dbprefix'] = $this->db_prefix; 
    $db_config['pconnect'] = ($this->input->post('pconnect')) ? TRUE : FALSE; 

    $this->CI =& get_instance(); 
    $this->CI->load->helper('file'); 

    $prototype = array(
         'hostname' => 'localhost', 
         'username' => '', 
         'password' => '', 
         'database' => '', 
         'dbdriver' => 'mysql', 
         'dbprefix' => 'mojo_', 
         'pconnect' => TRUE, 
         'db_debug' => FALSE, 
         'cache_on' => FALSE, 
         'cachedir' => '', 
         'char_set' => 'utf8', 
         'dbcollat' => 'utf8_general_ci' 
        ); 

    // Now we read the file data as a string 
    $config_file = read_file(APPPATH.'config/database'.EXT); 

    // Dollar signs seem to create a problem with our preg_replace 
    // so we'll temporarily swap them out 
    $config_file = str_replace('$', '@[email protected]', $config_file); 

    // Cycle through the newconfig array and swap out the data 
    if (count($dbconfig) > 0) 
    { 
     foreach ($dbconfig as $key => $val) 
     { 
      if ($val === 'y') 
      { 
       $val = TRUE; 
      } 
      elseif ($val == 'n') 
      { 
       $val = FALSE; 
      } 

      if (is_bool($val)) 
      { 
       $val = ($val == TRUE) ? 'TRUE' : 'FALSE'; 
      } 
      else 
      { 
       $val = '\''.$val.'\''; 
      } 

      $val .= ';'; 

      // Update the value 
      $config_file = preg_replace("#(\@s\@db\[(['\"])".$active_group."\\2\]\[(['\"])".$key."\\3\]\s*=\s*).*?;#", "\\1$val", $config_file); 
     } 
    } 

    // Put the dollar signs back 
    $config_file = str_replace('@[email protected]', '$', $config_file); 

    // Just to make sure we don't have any unwanted whitespace 
    $config_file = trim($config_file); 

    // Write the file 
    $fp = fopen($this->database_path, FOPEN_WRITE_CREATE_DESTRUCTIVE); 

    flock($fp, LOCK_EX); 
    fwrite($fp, $config_file, strlen($config_file)); 
    flock($fp, LOCK_UN); 
    fclose($fp); 

나는이 테스트를하지 않은,하지만 난 내 자신의 프로젝트 중 하나와 같은 비슷한을 구현하기 위해 노력하고있어.

조금 더 가까이 올 수 있기를 바랍니다.

+0

감사합니다. Repox For Reply. –

1

줌라, 워드 프레스 등과 같은 no automated CI installer이 있으므로 불가능합니다. 따라서 그러한 기회가 필요한 경우 직접 설치 프로그램을 만들어야합니다. 그렇게한다면 커뮤니티와 공유하는 것을 잊지 마십시오.

0

그런 접근 방법이 좋습니다. 당신이해야 할 일은 autoload.php 파일에서 DB 라이브러리를 자동으로로드하는 것을 피하는 것입니다. 그렇지 않으면 페이지를로드 할 때마다 오류가 발생하게됩니다. 그런 다음 설치 프로그램에서 실행되는 하나를 제외해야하고 DB 액세스를 필요로하는 모든 컨트롤러에이를 확장 할 수 있습니다

function __construct() 
{ 
    $this->load->database(); 
} 

:

$autoload['libraries'] = array(<strike>'database',</strike> 'form_validation', 'cart','session'); 

당신은있는 MY_Controller을 가질 수 있습니다.

2

아직 테스트하지는 않았지만 두 가지 해결책을 찾았습니다.

일종의 설치 프로그램이있는 Codeigniter 프레임 워크를 기반으로하는 많은 프로젝트가 있습니다. "Repox"처럼 MojoMotor에서이 특정 작업을 처리하는 핵심/Config.php 확장 클래스가 있으며 Expression Engine에도이 기능이 있습니다. 슬프게도 상업 라이센스하에 있으며 사용할 수 없습니다.

이러한 솔루션을 사용하는 무료 응용 프로그램은 Ionize CMS입니다.

이 클래스에서보세요 : https://github.com/ionize/ionize/blob/master/install/class/Config.php

두 번째는 "파일"이라는 불꽃에있다. 여기에서 찾을 수 있습니다 : http://getsparks.org/packages/files/versions/HEAD/show

명백한 제한은 설정 파일을 다시 작성한다는 것입니다.

"codeigniter github issue 1058"(Google의 링크)에도 다소 지적되었지만, 슬프게도 개발자는이를 닫기로 결정했습니다.

필자는 이러한 기능이 프레임 워크에 구현되지 않은 이유를 개인적으로 이해하지 못합니다. 설치시 구성 파일을 편집하는 데 사용할 수있을뿐만 아니라 제어판에서도 사용할 수 있습니다.

관련 문제