Php Codeigniter锚定标记超链接到控制器中的表单,但数据显示在表外
我正在使用Codeigniter 3并尝试CRUD操作。我已经创建了基本crud操作,并在表中显示数据,但是如果我想输入其他数据,我已经将表下方控制器中的段落标记链接到表单控制器 问题是,当我点击链接输入另一个数据时,它会将我重定向到controller中的原始表单,但当我输入数据并提交时,数据显示在段落标记的表格下方。 我无法理解为什么会发生这种情况,因为控制器是相同的 我以前在控制器中重定向时遇到过类似的问题。我在提交后将页面重定向到show_form()controller,这基本上是将页面重定向到$this->load->view('learn/view_form'); 其中我保留了一个条件,即如果没有数据,请单击以输入。现在,当它重定向到show_form()控制器时,即使数据存在,它也会进入else状态 控制器Php Codeigniter锚定标记超链接到控制器中的表单,但数据显示在表外,php,codeigniter,codeigniter-3,Php,Codeigniter,Codeigniter 3,我正在使用Codeigniter 3并尝试CRUD操作。我已经创建了基本crud操作,并在表中显示数据,但是如果我想输入其他数据,我已经将表下方控制器中的段落标记链接到表单控制器 问题是,当我点击链接输入另一个数据时,它会将我重定向到controller中的原始表单,但当我输入数据并提交时,数据显示在段落标记的表格下方。 我无法理解为什么会发生这种情况,因为控制器是相同的 我以前在控制器中重定向时遇到过类似的问题。我在提交后将页面重定向到show_form()controller,这基本上是将页
<?php
defined('BASEPATH') OR exit("No direct script access allowed");
class Learning extends CI_Controller{
public function __construct(){
parent::__construct();
$this ->load->helper("url");
$this->load->model("tatti_test");
$this->load->database();
$this->load->helper();
}
//functions should be passed here
//creating a function
function start_learn() {
//this varible
$this->load->view('learn/start_learn');
}
function start_crud(){
$this->load->view('learn/form');
}
function show_form(){
$this->load->view("learn/view_form");
}
function insert_form(){
$name = $this->input->post("u_name");
$email = $this->input->post("u_email");
$mobile = $this->input->post("u_mobile");
//File Uploading
$config['upload_path']="./assets/images/";
$config["allowed_types"]="gif|jpg|png";
$config['encrypt_name']=true;
$this->load->library("upload",$config);
if(!$this->upload->do_upload("u_file")){
$file='noimage.png';
}
else {
$filework = $this->upload->data();
$file =$filework['file_name'];
}
$data = array(
"name"=>$name,"email"=>$email,"mobile"=>$mobile,"file_name"=>$file
);
$this->tatti_test->insert_tatti($data);
redirect("learning/view_form");
}
function view_form(){
$data['returned_data']=$this->tatti_test->show_form();
$this->load->view("learn/view_form",$data);
}
function delete_entry(){
$id=$this->uri->segment(3);
$data=$this->tatti_test->for_unlink($id);
$filepath="./assets/images/".$data['file_name'];
unlink($filepath);
$this->tatti_test->delete_entry($id);
redirect('learning/view_form');
}
function time_to_update(){
$id=$this->uri->segment(3);
$data['fetched_update_entry']=$this->tatti_test->update_entry($id);
$this->load->view("learn/update.php",$data); //bus associative array hi leta hai
}
function up_db(){
$name =$this->input->post('up_name');
$email = $this->input->post('up_email');
$mobile = $this->input->post('up_mobile');
$file = $this->input->post('up_file');
$id = $this->input->post('up_id');
//File Uploading
$config['upload_path']="./assets/images/";
$config["allowed_types"]="gif|jpg|png";
$config['encrypt_name']=true;
$this->load->library("upload",$config);
if(!$this->upload->do_upload("up_file")){
$data= $this->tatti_test->remove_prev($id);
$file=$data['file_name'];
}
else {
$data= $this->tatti_test->remove_prev($id);
$path="./assets/images/".$data['file_name'];
unlink($path);
$filework = $this->upload->data();
$file =$filework['file_name'];
}
$data = array(
"name"=>$name,"email"=>$email,"mobile"=>$mobile,"file_name"=>$file
);
$this->tatti_test->up_nw($data,$id);
redirect('learning/view_form');
}
} /*this accesses command from main ci controller */
?>
<?php
class Tatti_test extends CI_Model{
function insert_tatti($insert_data){
$this->db->insert("f_form",$insert_data);
}
function show_form(){
$query = $this->db->get("f_form");
$response=[];
if ($query->num_rows() > 0){
$response = $query->result_array();
}
else {
$response = 0;
}
return $response;
}
function for_unlink($id){
$this->db->where("id",$id);
$query = $this->db->get("f_form");
$response=[];
foreach ($query->result_array() as $rows){
return $response = $rows;
}
}
function delete_entry($id){
$this->db->where("id",$id);
$this->db->delete("f_form");
}
function update_entry($id){
$this->db->where("id",$id);
$query = $this->db->get("f_form");
$response = [];
if($query->num_rows() > 0 ){
foreach($query->result_array() as $rows);
$response = $rows;
}
return $response;
}
function up_nw($introduced_data,$id){
$this->db->set($introduced_data);
$this->db->where('id',$id);
$this->db->update('f_form');
}
function remove_prev($id){
$this->db->where('id',$id);
$query = $this->db->get('f_form');
$response = [];
foreach($query->result_array() as $rows){
$response=$rows;
}
return $response;
}
}
?>
查看
<?php $this->load->view("common/header.php");
if ($returned_data != 0){ ?>
<table border='1'>
<tr>
<th>Sr No</th>
<th>Name</th>
<th>Password</th>
<th>Mobile</th>
<th>Email</th>
<th>Final Name</th>
<th>Delete</th>
<th>View</th>
</tr>
<?php $i=0; foreach ($returned_data as $key=>$d){
?>
<tr>
<td>
<?php echo ++$i; ?>
</td>
<td>
<?php echo $d['name'];?>
</td>
<td>
<?php echo $d['mobile'];?>
</td>
<td>
<?php echo $d['email'];?>
</td>
<td>
<?php echo $d['file_name'];?>
</td>
<td>
<img src="<?php echo base_url().'/assets/images/'.$d['file_name'];?>" width="100px" ; height="100px" />
</td>
<td><a href="<?php echo base_url().'index.php/learning/time_to_update/'.$d['id'];?>">Edit</a></td>
<td><a href="<?php echo base_url().'index.php/learning/delete_entry/'.$d['id'];?>">Delete</a></td>
</tr>
</table>
<p>Add another entry
<?php echo anchor("learning/start_crud"," here "); ?>
</p>
<?php } ?>
<?php } else { ?>
<p>No data to show please click
<?php echo anchor("learning/start_crud"," here "); ?>to enter</p>
<?php } ?>
<?php $this->load->view("common/footer.php");
高级职员
名称
密码
可移动的
电子邮件
姓
删除
看法
“width=“100px”;height=“100px”/>
添加另一个条目
没有要显示的数据,请单击
进入
这是单击下表链接时数据的显示方式
您的html格式混乱。您应该将结束
置于foreach循环之外,或者提前结束
还将添加另一个条目链接移动到foreach循环之外。因此它只出现一次,并且您的文档格式不会混乱
您可以改为使用此固定视图:
<?php $this->load->view("common/header.php");
if ($returned_data != 0){ ?>
<table border='1'>
<tr>
<th>Sr No</th>
<th>Name</th>
<th>Password</th>
<th>Mobile</th>
<th>Email</th>
<th>Final Name</th>
<th>Delete</th>
<th>View</th>
</tr>
<?php $i=0; foreach ($returned_data as $key=>$d){
?>
<tr>
<td>
<?php echo ++$i; ?>
</td>
<td>
<?php echo $d['name'];?>
</td>
<td>
<?php echo $d['mobile'];?>
</td>
<td>
<?php echo $d['email'];?>
</td>
<td>
<?php echo $d['file_name'];?>
</td>
<td>
<img src="<?php echo base_url().'/assets/images/'.$d['file_name'];?>" width="100px" ; height="100px" />
</td>
<td><a href="<?php echo base_url().'index.php/learning/time_to_update/'.$d['id'];?>">Edit</a></td>
<td><a href="<?php echo base_url().'index.php/learning/delete_entry/'.$d['id'];?>">Delete</a></td>
</tr>
<?php } ?>
</table>
<p>Add another entry
<?php echo anchor("learning/start_crud"," here "); ?>
</p>
<?php } else { ?>
<p>No data to show please click
<?php echo anchor("learning/start_crud"," here "); ?>to enter</p>
<?php } ?>
<?php $this->load->view("common/footer.php");
高级职员
名称
密码
可移动的
电子邮件
姓
删除
看法
“宽度=“100px”;高度=“100px”/>
添加另一个条目
没有要显示的数据,请单击
进入
我知道你想做凝乳,
首先,尝试以下方法来改进您的代码并填充缺少的codeigniter库:
对于您的代码:
- 没有以show_form()的形式传递到视图的数据
- 您应该检查表单提交和加载视图的条件
- 简单的做法是使用现成的脚本遵循最佳实践
希望这将是有用的,因此,基本上,新信息显示在错误的位置,例如不在表格中。。这很混乱,因为其他条目的位置正确吗?是在错误的地方…这是其中一个格式化就是一切的例子。