2017-11-12 7 views
1

저는 PHP로 초보자입니다. 나는 간단한 숙제가있다. 업데이트, 삭제, 삽입 및 XAMPP에있는 단일 DB에서 선택해야합니다. Mysqli 라이브러리를 사용하여이 작업을 수행했으며 이제는 codeigniter를 사용하여 수행하도록 요청 받았습니다. 나는 CodeIgniter 파일을 XAMPP 파일의 htdocs 안에 넣었고, 나는 database.php를 편집하여 라이브러리 배열에 데이터베이스를 추가하는 autoload.php의 자동 연결을 가능하게 만들도록 문서를 읽었다. 내 의심은 다음에 올 것이다. 내가 sudo 난 htdocs에 더 이상 내 파일을 넣지 않아도되지만 codeigniter 파일 안에있는 응용 프로그램에. 권리? 왜냐하면 내가 htdocs에서 파일을 생성하고 쿼리를 생성했기 때문에 단순히 연결하지 않기 때문입니다. 영어로 죄송합니다.codeigniter를 사용하여 phpmyadmin db를 연결하는 파일을 찾으십시오.

답변

0

@rene 컨트롤러 파일을 만들었습니까?

당신은 내부의 컨트롤러를 만들 필요가 없습니다 경우 응용 프로그램/컨트롤러/SomeName.php 참조 : https://www.codeigniter.com/user_guide/general/controllers.html

당신이 응용 프로그램/모델에서 모델을 만들 필요가 그 후/SomeName_m.php 은 참조 : https://www.codeigniter.com/user_guide/general/models.html

모델 내에서 모든 데이터베이스 쿼리가 필요합니다. 참조 : 데이터베이스를 로컬 호스트에서 수행

Go to application/config/autoload.php 
and find $autoload['libraries'] = array(); 
replace it by $autoload['libraries'] = array('database'); 

데이터베이스 설정을로드 할 것을 요구 한 후

- application/config/database.php 

    $db['default'] = array(
    'dsn' => '', 
    'hostname' => 'localhost', 
    'username' => 'root', 
    'password' => '', 
    'database' => 'your_database_name' 
............ 
............. 

내부 데이터베이스 구성 파일을 찾을 수 있습니다 https://www.codeigniter.com/user_guide/database/queries.html

0

. 는 이제 모델의 기능을 명중 곳에서 컨트롤러 파일을 생성하고 예를 컨트롤러에 대한 쿼리 을 실행 모델 클래스를 만듭니다 Welcome.php

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

class Welcome extends CI_Controller { 

/** 
* Index Page for this controller. 
* 
* Maps to the following URL 
*  http://example.com/index.php/welcome 
* - or - 
*  http://example.com/index.php/welcome/index 
* - or - 
* Since this controller is set as the default controller in 
* config/routes.php, it's displayed at http://example.com/ 
* 
* So any other public methods not prefixed with an underscore will 
* map to /index.php/welcome/<method_name> 
* @see https://codeigniter.com/user_guide/general/urls.html 
*/ 
public function index() 
{ 
    $data['result'] = $this->home_model->getTodayResult();// Home_model this is the model class where we put the sql queries 

    $this->load->view('frontend/partials/header');// template header 

    $this->load->view('frontend/index', $data); //template main page and data which passed to the view or html or template 

    $this->load->view('frontend/partials/footer');// template footer 
} 
} 

응용 프로그램/모델 내부 Home_model 만들기/Home_model.php

<?php 
class Home_model extends CI_Model 
{ 
    public function getTodayResult(){ 
    $query = "select * from users"; 
    $res = $this->db->query($query); 
    return $res->result(); 
} 
} 

문제가 있으면 의견을 추가하십시오.