[英]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.