[英]How can I allow controller access only for form submission?
我在CodeIgniter中有一個控制器。 我不想讓任何人訪問控制器。 只能在提交表單時訪問此控制器。 我該怎么做? 下面給出了控制器代碼。
public function editad($uniqueid = ''){
$this->load->model('Ads');
$this->load->model('Postingad');
$data =
if($uniqueid == ''){
show_404();
}
$checkbox = $this->Ads->products($uniqueid);
$product = json_decode($this->input->post('products'));
$checked = $this->input->post('product_category');
for($i = 0; $i < count($checkbox); $i++){
$checkboxes[] = $checkbox[$i]['Product'];
}
for($i = 0; $i < count($checkbox); $i++){
if(!in_array($checkbox[$i]['Product'], $product)){
if($checkbox[$i]['Image'] != 'http://wallpapercraze.com/images/wallpapers/nowallpaper-585747.jpeg'){
unlink('./uploads/'.$checkbox[$i]['Image']);
}
$this->Ads->deletecheckbox($uniqueid,$checkbox[$i]['Product']);
}
}
$files = array(
'electronics'=>'efile',
'kitchen'=>'kfile',
'decoratives / Interior'=>'dfile',
'Home Decor'=>'hdfile',
'Furnitures'=>'ffile',
'Toys'=>'tfile',
'Vehicles'=>'vfile',
'Other'=>'ofile'
);
$config['upload_path'] = './uploads/'.$uniqueid;
$config['allowed_types'] = 'gif|jpg|png';
$this->load->library("upload", $config);
for($i = 0; $i < count($checked); $i++){
$filenamefield = $files[$checked[$i]];
if($_FILES[$filenamefield]['size'] > 0){
if($this->upload->do_upload($filenamefield)){
$upload_data = $this->upload->data();
$filename = $upload_data['file_name'];
$checkboxinfo = array(
'UniqueID'=>$uniqueid,
'Product'=>$checked[$i],
'Image'=>$uniqueid.'/'.$filename
);
$this->Postingad->checkbox($checkboxinfo);
}
}
else{
$checkboxinfo = array(
'UniqueID'=>$uniqueid,
'Product'=>$checked[$i],
'Image'=>'http://wallpapercraze.com/images/wallpapers/nowallpaper-585747.jpeg'
);
$this->Postingad->checkbox($checkboxinfo);
}
}
echo '<pre>';
print_r($upload_data);
echo '</pre>';
}
以_
開頭的函數名稱。
在某些情況下,您可能希望某些功能對公共訪問隱藏。 要將函數設為私有,只需添加下划線作為名稱前綴即可,並且不會通過URL請求提供。
在以下類似問題中閱讀有關此的更多信息: CodeIgniter-私有函數
public function editad($uniqueid = ''){
應該是public function _editad($uniqueid = ''){
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.