添加和编辑不工作它的唯一显示页面错误plz帮助修复这个PHP codignitor [英] Add and edit not work its only show page error plz help to fix this in PHP codignitor

查看:49
本文介绍了添加和编辑不工作它的唯一显示页面错误plz帮助修复这个PHP codignitor的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

user.php



<?php

定义('BASEPATH')或退出('不允许直接访问脚本' );



类用户扩展CI_Controller {

函数__construct(){

parent :: __ construct() ;

$ this-> load-> model('user / user_model','m');

}



函数索引(){

$ data ['user'] = $ this-> m-> get_user();

$ this - > load-> view('user / user_view',$ data);

}



function add(){

$ this-> load-> view('user / user_view_add');

}



function submit(){

$ this-> m-> submit();

}



函数编辑($ id){

$ data ['get_edit'] = $ this-> m-> get_edit($ id);

// print_r ($ data);

$ this-> load-> view('user / user_view_edit',$ data);

}



function update(){

$ this-> m-> update();

}



}





user_model.php



<?php

定义('BASEPATH')或退出('不允许直接访问脚本');



类User_model扩展CI_Model {

函数get_user(){

$ query = $ this-> db-> get('tbluser');

返回$ query->结果();

}



函数submit(){

$ arr = array(

'username'=> $ this-> input-> post('txtusername'),

'sexual'=> $ this-> input-> post('slogender'),

'address'=> $ this-> input-> post('txtaddress')

);

// print_r($ arr); exit();

$ this-> db-> insert('tbluser',$ arr);

if($ this-> db-> affected_rows()> 0){

redirect(base_url()。'user / user /');

}

}



函数get_edit($ id){

$ query = $ this-> db-> get_where('tbluser',array(' user_id'=> $ id));

返回$ query-> row();

}



函数更新(){

$ id = $ this-> input-> post('txtid');

// echo $ id; exit();

$ arr = array(

'username'=> $ this-> input-> post('txtusername'),
'sexual'=> $ this-> input-> post('slogender'),

'address'=> $ this-> input-> post('txtaddress')

);

$ this-> db-> where('user_id',$ id);

$ this-> db-> update('tbluser',$ arr);

if($ this-> db-> affected_rows()> 0){

redirect(base_url()。'user / user');

}

}



}



?>



user_view.php





<!DOCTYPE html PUBLIC - // W3C // DTD XHTML 1.0 Transitional // ENhttp://www.w3.org/TR/xhtml1 /DTD/xhtml1-transitional.dtd\">





< meta http-equiv =Content-Typecontent = text / html; charset = utf-8/>

< title>用户









<啊ref =<?= base_url();?> index.php / user / add> Add new



<?php / * GT?; <?php print_r($ user); ?><?php * /?>

<?php

$ n = 1;

foreach($ user as as $ row):

$性别=($ row->性别== 1)?'男':'女';



?>

<?php $ n ++; endforeach; ?>

用户名 性别 地址 行动
<?= $ n?> <?= $ row-> username; ?> <?= $ gender; ?> <?= $ row->地址; ?> 编辑

删除











user_view_add.php



<?= form_open('user / user / submit'); ?>





用户名 <?= form_input('txtusername'); ?>
性别 <?= form_dropdown('slogender',数组('1'=>'男','2' => '女')); ?>
地址 <?= form_textarea('txtaddress'); ?>
<?= form_submit('btnsubmit','保存'); ?>




<?= form_close(); ?>





user_view_edit.php





<?= form_open('user / user / update'); ?>





用户名 <?= form_input('txtusername',$ get_edit-> username); ?>

<?= form_hidden('txtid',$ get_edit-> user_id); ?>

性别 <?= form_dropdown('slogender',array('1'=> ;'男','2'=>'女'),$ get_edit->性别); ?>
地址 <?= form_textarea('txtaddress',$ get_edit->地址); ?>
<?= form_submit('btnsubmit','保存'); ?>




<?= form_close(); ?>





错误:编辑和添加都找不到对象

路径:模型/用户/user_model.php

view / user / user_view.php

/user_view_add.php

/user_view_edit.php



我尝试过:



错误:找不到对象编辑和添加

路径:model / user / user_model.php

view / user / user_view.php

/user_view_add.php

/ user_view_edit.php

user.php

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class User extends CI_Controller {
function __construct() {
parent::__construct();
$this->load->model('user/user_model','m');
}

function index() {
$data['user'] = $this->m->get_user();
$this->load->view('user/user_view', $data);
}

function add() {
$this->load->view('user/user_view_add');
}

function submit() {
$this->m->submit();
}

function edit($id) {
$data['get_edit'] = $this->m->get_edit($id);
//print_r($data);
$this->load->view('user/user_view_edit', $data);
}

function update() {
$this->m->update();
}

}


user_model.php

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class User_model extends CI_Model {
function get_user() {
$query = $this->db->get('tbluser');
return $query->result();
}

function submit() {
$arr = array(
'username'=>$this->input->post('txtusername'),
'gender'=>$this->input->post('slogender'),
'address'=>$this->input->post('txtaddress')
);
//print_r($arr); exit();
$this->db->insert('tbluser', $arr);
if($this->db->affected_rows()>0) {
redirect(base_url().'user/user/');
}
}

function get_edit($id) {
$query = $this->db->get_where('tbluser', array('user_id'=>$id));
return $query->row();
}

function update() {
$id = $this->input->post('txtid');
//echo $id; exit();
$arr = array(
'username'=>$this->input->post('txtusername'),
'gender'=>$this->input->post('slogender'),
'address'=>$this->input->post('txtaddress')
);
$this->db->where('user_id', $id);
$this->db->update('tbluser', $arr);
if($this->db->affected_rows() > 0) {
redirect(base_url().'user/user');
}
}

}

?>

user_view.php


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>user




Add New

<?php /*?> <?php print_r($user); ?><?php */?>
<?php
$n=1;
foreach($user as $row):
$gender = ($row->gender == 1)?'Male':'Female';

?>
<?php $n++; endforeach; ?>

No Username Gender Address Action
<?= $n ?> <?= $row->username; ?> <?= $gender; ?> <?= $row->address; ?> Edit
Delete





user_view_add.php

<?= form_open('user/user/submit'); ?>


Username <?= form_input('txtusername'); ?>
gender <?= form_dropdown('slogender', array('1'=>'Male', '2'=>'Female')); ?>
Address <?= form_textarea('txtaddress'); ?>
<?= form_submit('btnsubmit', 'Save'); ?>


<?= form_close(); ?>


user_view_edit.php


<?= form_open('user/user/update'); ?>


Username <?= form_input('txtusername', $get_edit->username); ?>
<?= form_hidden('txtid', $get_edit->user_id); ?>
gender <?= form_dropdown('slogender', array('1'=>'Male', '2'=>'Female'), $get_edit->gender); ?>
Address <?= form_textarea('txtaddress', $get_edit->address); ?>
<?= form_submit('btnsubmit', 'Save'); ?>


<?= form_close(); ?>


error: object not found for both edit and add
path : model/user/user_model.php
view/user/user_view.php
/user_view_add.php
/user_view_edit.php

What I have tried:

error: object not found for both edit and add
path : model/user/user_model.php
view/user/user_view.php
/user_view_add.php
/user_view_edit.php

推荐答案

this-> load-> model('user / user_model','m');

}



函数索引(){
this->load->model('user/user_model','m');
}

function index() {


data ['user'] =
data['user'] =


this-> m-> get_user();
this->m->get_user();


这篇关于添加和编辑不工作它的唯一显示页面错误plz帮助修复这个PHP codignitor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆