'언어&플랫폼/Codeigniter'에 해당되는 글 2건

  1. 2015.04.07 :: [codeigniter] ubuntu index.php 죽이기
  2. 2015.04.01 :: [codeigniter] mongodb 연동
언어&플랫폼/Codeigniter 2015. 4. 7. 15:32

환경 : Ubuntu 14.04.1 LTS \n \l

WAS : apach2


moe_rewrite module 활성화?

$ sudo a2enmod rewrite

$ sudo service apache2 restart



{CI 폴더}/application/config/config.php 수정

$config['index_page'] = '';



{document root}/.htaccess 수정/생성

<IfModule mod_rewrite.c>

    RewriteEngine On

    RewriteCond %{REQUEST_FILENAME} !-f

    RewriteCond %{REQUEST_FILENAME} !-d

    RewriteRule ^(.*)$ index.php/$1 [L]


    <Files "index.php">

    AcceptPathInfo On

    </Files>

</IfModule>             



/etc/apach2/site-available/000-default.conf 수정

<Directory "/var/www/html"> AllowOverride All </Directory>


$ sudo service apache2 restart









참고


http://stackoverflow.com/questions/1445385/how-to-remove-index-php-in-codeigniters-path


http://www.dev-metal.com/enable-mod_rewrite-ubuntu-14-04-lts/

'언어&플랫폼 > Codeigniter' 카테고리의 다른 글

[codeigniter] mongodb 연동  (0) 2015.04.01
posted by cozyboy
:
언어&플랫폼/Codeigniter 2015. 4. 1. 22:11

환경 : Ubuntu 14.04.1 LTS

 

codeigniter mongoDB 설치 되어있다는 가정하에 진행한다.

 

codeigniter 다운로드 주소 

http://www.codeigniter.com/download


 

 

  1. PHP Driver 설치

 

$ sudo pecl install mongo

 

 

$ php -i | grep 'Configuration File'

Configuration File (php.ini) Path => /etc/php5/cli

Loaded Configuration File => /etc/php5/cli/php.ini

 

php.ini 수정 (/etc/php5/cli/php.ini)

extension=mongo.so

 

 

$ sudo apt-get install php5-dev php5-cli php-pear

 

 

  1. Cogeigniter mongodb library 다운 설치

$ git clone https://github.com/vesparny/cimongo-codeigniter-mongodb-library.git

$ cd cimongo-codeigniter-mongodb-library/

$ cp config/* /var/www/html/Ci/application/config/

$ cp libraries/* /var/www/html/Ci/application/libraries/ -rf

 

 

  1. DB 정보 설정 (자신의 DB 세팅에 맞게 설정)

$ vim /var/www/html/Ci/application/config/cimongo.php 

// Generally localhost

$config['host'] = "localhost";

// Generally 27017

$config['port'] = 27017;

// The database you want to work on

$config['db'] = "test";

// Required if Mongo is running in auth mode

$config['user'] = "";

$config['pass'] = "";

 

  1. mongodb 사용하기

    • 기본 컨트롤러 정하기( Ci/application/config/routes.php)

$route['default_controller'] = "login";

 

  • 라이브러리 자동 로드(Ci/application/config/autoload.php)

$autoload['libraries'] = array('cimongo/cimongo');

 

//자동으로 라이브러리를 부르지 않으려면 컨트롤 페이지에

//$this->load->library("cimongo/cimongo"); 로드 라이브러리를 사용해야 한다.

 

  • cimongo 라이브러리 사용 ( Ci/controllers/login.php)

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

class Login extends CI_Controller {

public function index()

{

$this->load->view('login');     //페이지 login.php 부르기

}

 

public function test()

{

$count= $this->cimongo->count_all('job');

echo $count;

 

$mongo_data = $this->cimongo->get("job");

foreach($mongo_data->result_array() as $row) {

echo sprintf('x:%d,y:%s <br>',$row['rank'], $row['url']);

}

 

 

}

}

?>

 

  • 동작 확인 (Ci/application/view/login.php 삽입된 js 파일 호출부분)

function test(){

$.ajax({

url:'index.php/login/test/',

success : function(data) {

console.log(data);

 },

 error : function(request, status, error) {

console.log("code:"+request.status+"\n"+"message:"+request.responseText+"\n"+"error:"+error);

 },

});

 

}

 

$(document).ready(function() {

test();

});

 

 


 

  • 라이브러리 사용

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

class Welcome extends CI_Controller
{
  // Insert Operation
 
public function mongo_insert_test()     
  {
     $this->load->library("cimongo/cimongo");
    
for($i=0;$i<25;$i++) {
        $this->cimongo
            ->insert("testData", array("x" => $i, "y" => 25-$i ));
    
}
  }

// Select Operation
 
public function mongo_select_test()
  {
     $this->load->library("cimongo/cimongo");
    
$mongo_data = $this->cimongo->get("testData");
     foreach($mongo_data->result_array() as $row) {
        echo sprintf('x:%d,y:%d <br>',$row['x'],$row['y']);
    
}
  }
 
  // Update Operation
 
public function mongo_update_test()
  {
     $this->load->library("cimongo/cimongo");
    
$result = $this->cimongo->where(array("x" => 24 ))
                    ->set(array("x" => 25 ))->update("testData");
    
echo $result
  }

// Delete Operation
 
public function mongo_delete_test()
  {
     $this->load->library("cimongo/cimongo");
    
$result = $this->cimongo->where(array("x" => 25 ))
                    ->delete("testData");
    
echo $result;
  }

}

?>

 


 


 



 



[참고]

mongoDB Driver 설치

http://docs.mongodb.org/ecosystem/drivers/php/

 

PHP Fatal error:  Class 'MongoClient' not found  문제 해결

http://stackoverflow.com/questions/24533938/class-mongoclient-not-found

 

cimongo 함수 사용

https://txcom2003.wordpress.com/2015/02/04/codeigniter-tokumx/

 

참고만

http://mudchobo.tistory.com/522

'언어&플랫폼 > Codeigniter' 카테고리의 다른 글

[codeigniter] ubuntu index.php 죽이기  (0) 2015.04.07
posted by cozyboy
: