[英]Something wrong with Codeigniter Callback validation
So I am creating a web app, it has this upload form where you can upload android APKs, this part of upload form is specifically for uploading a revised version of the old APK(In others words new version of the application). 因此,我正在创建一个Web应用程序,它具有此上传表单,您可以在其中上传android APK,这部分上传表单专门用于上传旧APK的修订版(换句话说,是应用程序的新版本)。
So I am doing all this in PHP, using CodeIgniter 2.x Since user is uploading a new version of old Application, I want the website to make sure the application being uploaded for this old application by user has same package name (Android Package file name) eg com.example.something 因此,我使用CodeIgniter 2.x在PHP中完成所有操作。由于用户正在上传旧版本的旧应用程序,因此我希望网站确保用户为此旧应用程序上载的应用程序具有相同的软件包名称(Android软件包文件名称),例如com.example.something
When the file upload is initiated, the file is parsed and the package name is put into the database, and a random generated hash of this file is stored in the session data as 'new_app_hash', the random hash of old file is in hidden input field called 'app_id'. 启动文件上传时,将对文件进行解析,并将包名称放入数据库中,并将此文件的随机生成的哈希作为“ new_app_hash”存储在会话数据中,旧文件的随机哈希位于隐藏的输入中名为“ app_id”的字段。
Now coming to the code: My controller has this in place to do the callback thing for app_id, and compare its information with 'new_app_hash' which is in the session. 现在来看代码:我的控制器已经准备好对app_id进行回调,并将其信息与会话中的“ new_app_hash”进行比较。 So, this callback is mainly for getting row information where the hash is 'app_id' and 'new_app_hash' in my database table, then compare the package names. 因此,此回调主要用于获取数据库表中哈希为“ app_id”和“ new_app_hash”的行信息,然后比较包名称。
$app_id = $this->input->post('app_id',TRUE);
if($app_id!='0'){ //only if app_id is not 0, else I dont want this to happen
$this->form_validation->set_rules('app_id','New Package','required|callback_packagerevname');
}
Model function used in callback: 回调中使用的模型函数:
public function check_checkpackagerevname($app_id,$sessionhash){
if($app_id!='0'){
$old_package = $this->getPackageInfo($app_id);
$new_package = $this->getPackageInfo($sessionhash);
if($old_package['package_name']==$new_package['package_name']){
///ok fine they are same, return true.
return TRUE;
}else{
return FALSE;
}
}else{
return TRUE;
}
}
GetPackageInfo(): GetPackageInfo():
public function getPackageInfo($hash){
$this->db->select('*');
$this->db->from('appstore_packages');
$this->db->where('hash',$hash);
$query = $this->db->get();
return $query->row_array();
}
My callback is as follows: 我的回调如下:
function callback_packagerevname($app_id){
$sessionAppHash = $this->session->userdata('new_hash_app');
$checking = $this->storeM->check_checkpackagerevname($app_id,$sessionAppHash);
if($checking==TRUE){
return TRUE;
}else{
$this->form_validation->set_message('packagerevname','The uploaded APK must have same package name as the parent app that you are trying to upload.');
return FALSE; ////// new apk doesnt have same package name.
}
}
I have tried checking if the form_validation rule is working, when i add some other sort of rule like greater_than[0] it does show me errors, but the callback doesn't work when form is submitted, though the callback function seems to work fine, when i visit it directly from the URL, with the 'new_app_hash' set in the session and putting app_id in URL, it does return true or false accordingly. 我试过检查form_validation规则是否正常工作,当我添加其他一些规则,例如Greater_than [0]时,确实显示了错误,但是提交表单时回调不起作用,尽管回调函数似乎可以正常工作,当我直接从URL中访问它,并在会话中设置了“ new_app_hash”并将app_id放入URL中时,它的确会返回true或false。
What could be wrong? 有什么事吗
PS If the question is a little confusing please comment, I am working on the project for like past 12 hours continuously, so I am a little you know. PS:如果您的问题有点令人困惑,请发表评论,我连续12个小时从事该项目的工作,所以我有点您知道。 :P :P
Edit: Ok it seems 12 hours really had it on me. 编辑:好吧,好像12个小时真的在我身上。 Thanks to praveen, I had named the callback method wrongly, instead of : 感谢praveen,我错误地命名了回调方法,而不是:
function callback_packagerevname($app_id){
}
It obviously should have been: 显然应该是:
function packagerevname($app_id){
}
You dont need callback_functionname
as callback event just remove callback_
and will work fine... 您不需要callback_functionname
作为回调事件,只需删除callback_
正常使用...
function packagerevname()
{
$app_id = $this->input->post('app_id');
//so on....
}
you can use set flash data 您可以使用设置的闪存数据
/* $this->form_validation->set_message('checkpackagerevname',
'The uploaded APK must have same package name as the parent app that you are trying to upload.'); */
$this->session->set_flashdata('checkpackagerevname',
'The uploaded APK must have same package name as the parent app that you are trying to upload.');
and can print 并可以打印
echo $this->session->flashdata('checkpackagerevname');
for more visit https://ellislab.com/codeigniter/user-guide/libraries/sessions.html 更多信息请访问https://ellislab.com/codeigniter/user-guide/libraries/sessions.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.