我已將會話包含在自動加載中,並且它在所有其他位置都可以工作。 我在檢索會話變量時遇到問題,它返回空結果。雖然在控制器中我設置了會話,但它工作正常。
這裏是我設置它在其他條件代碼:Codeigniter:無法將會話變量值從一個控制器獲取到另一個控制器
class Controller_catagory extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->model('generic_model');
$this->load->model('backend/model_post');
$this->load->model('backend/model_permissions');
}
public function index($param1='',$param2='')
{
$id=$this->generic_model->getAllRecords('dramas',array(
'drama_slug' => $param2),'drama_id','DESC');
// print_r($id);
if (!empty($id))
{
foreach ($id as $key)
{
$id = $key['drama_id'];
}
}
$data;
if (!empty($param1) && empty($param2))
{
$data["page"] = 'frontend/includes/view_alldramas';
$id = $this->generic_model->getAllRecords('channel',array('channel_slug' => $param1),'channel_id','DESC');
if (!empty($id))
{
foreach ($id as $key)
{
$id = $key['channel_id'];
$ch_slug= $data['ch_slug'] = $key['channel_slug'];
$this->session->set_userdata('ch_slug',$ch_slug);
}
}
$this->session->set_userdata('channel_capture',$id);
$data['dramas_pagination'] = $this->model_post->get_specific_channel_pagination(0,12,$id);
$data["get_dramas"]=$this->model_post->get_all_dramas();
$data['channels'] = $this->generic_model->getAllRecords('dramas', array('channel_fk' => $id),'drama_id','DESC');
}
else
{
// The id is printing right result
echo $id;
// Here i'm setting session, if i retrieve here its working
$this->session->set_userdata('drama_episode',$id);
$data['episodes_pagination'] = $this->model_post->get_specific_post_pagination(0,12,$id);
$data["get_episodes"]=$this->model_post->get_all_dramas();
$data['dramas'] = $this->generic_model->getAllRecords('post',$arr = array(
'dramas_fk' => $id),'id','DESC');
$data["page"] = 'frontend/includes/view_allposts';
}
$data['title'] = 'GLOBAL VIDEOS';
$data['heading'] = 'Dramas List';
$data["top"] = 'frontend/includes/top_home';
$this->load->view('frontend/index',$data);
}
}
}
現在,這裏是另一個類在那裏我試圖讓組會議的價值,但它不是檢索數據,我獲得空記錄。
注:我做同樣的事情與「channel_capture」,我成功地獲取其值
class Home extends CI_Controller {
public function __construct()
{
$data = array();
parent::__construct();
$this->load->model('backend/model_post');
$this->load->model('generic_model');
}
public function ajax_posts()
{
$start= $_GET['start'];
// it gives empty result here don't know why
$id = $this->session->userdata('drama_episode');
//prints nothing
echo "This key: ".$id;
$post_pagination=$this->model_post->get_specific_post_pagination($start, 12, $id);
var_dump($post_pagination);
$str='';
$base_url=base_url();
if (empty($post_pagination))
{
return false;
}
foreach($post_pagination as $post)
{
$str.= '<div class="col-lg-3 col-sm-6 col-md-4 epi_height" >';
$str.= '<a href='.$base_url.$post['slug'].'>';
$str.= '<img class="img-responsive" src='.$base_url.$post['thumbnail'].' alt="recent dramas" />';
$str.= $post['title'];
$str.= '</a>';
$str.= '</div>';
}
echo $str;
}
}
對不起,我剛纔忘了說,我在自動加載包含會話 –