, 당신은 당신이 고유 식별자를 전달 getCompanyDetailsByID()
, 같은 모델의 기능이 무엇인가를 호출 할 것이고, 그에 따라 하나의 결과 객체를 반환 :
<?php
function getCompanyDetailsByID($id)
{
$this->db->select('coreCompanyName, coreContactName, coreContactEmail');
$this->db->where('coreCompanyID', $id);
return $this->db->get('core')->first_row();
}
"coreCompanyID"를 기본 열 이름으로 바꿉니다.
ADDITION :
여기 당신은 모든 기업의 정보를 얻을 것입니다 방법 :
<?php
function getCompanyDetails()
{
$this->db->select('coreCompanyName, coreContactName, coreContactEmail');
return $this->db->get('core')->result();
}
// And then in your controller:
function display()
{
$this->load->model('core');
$companies = $this->core->getCompanyDetails();
// Here's where you would probably load the data into a view
foreach ($companies as $company)
{
echo $company->coreCompanyName.'<br />';
}
}
최종 답변을! : P
<?php
function companyDetails()
{
static $details;
if (!$details)
{
$this->db->select('coreCompanyName, coreContactName, coreContactEmail');
$this->db->where('coreCompanyID', $id);
$details = $this->db->get('core')->first_row();
}
return $details;
}
지금 당신이 그 함수를 여러 번 호출 할 수 있으며, 그것은 단지 예를 들어, 한 번 데이터베이스에 접속합니다
<?php
echo $this->core_model->companyDetails()->coreCompanyName;
// do stuff
echo $this->core_model->companyDetails()->coreContactName;
// more stuff
echo $this->core_model->companyDetails()->coreContactEmail;
한 번만 데이터베이스에 접속하는 모든.
그렇다면 이드를 모델에 전달해야한다는 것을 알고 싶습니까? –
원하는 결과를 어떻게 알 수 있습니까? 모든 회사를 얻고 싶다면 다른 이야기입니다. 답을 바꾸어야합니다. – landons
하지만이 데이터베이스에는 하나의 회사 만 있으므로 데이터를 추출하려고했습니다. –