さて、コントローラーにこのコードスニペットがあります。ただし、これはすべてDB駆動型であり、実際にはモデルに含まれている必要があります。ただし、IFステートメントでわかるように、$dataをビューに渡す必要があります。結果に基づく。このコーディングのチャックをモデルのメソッドに貼り付けようとしました(コントローラーを介してモデルメソッドを呼び出します)が、$data[update_prompt]文字列がビューによって呼び出されません...
このコードをモデルに変換するにはどうすればよいですか?$ data値をコントローラーに送り返して、ビューに埋め込みますか?
// show appropriate upgrade message if user has free account
$id = $this->session->userdata('user_id');
$this->db->select('subscription'); // select the subscription column
$this->db->where('id', $id); //find id in table that matches session id
$query = $this->db->get("subscriptions"); // connect to this database
$subscribe = $query->result_array(); //returns the result of the above
if($subscribe[0]['subscription'] == 'freebie') // if subscription column equals 'freebie' in the $subscribe array, do this:
{
$data['update_prompt'] = $this -> load -> view('shared/upgrade_subscription', '', TRUE); // adds view within view, $update_prompt
}
else
{
$data['update_prompt'] = '';
}