解决PHP codignitor对象未找到问题, [英] Solve PHP codignitor object not found proble,

查看:79
本文介绍了解决PHP codignitor对象未找到问题,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

user.php



<?php 
defined('BASEPATH')OR exit('无直接脚本访问权限允许');

class用户扩展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();
}

}







user_model.php





<?php 
defined('BASEPATH')OR exit('无直接脚本访问权限)允许');

class User_model扩展CI_Model {
function get_user(){
$ query = $ this-> db-> get('tbluser');
返回$ query-> result();
}

函数submit(){
$ arr = array(
'username'=> $ this-> input-> post('txtusername '),
'gender'=> $ this-> input-> post('slogender'),
'address'=> $ this-> input-> post( 'txtaddress')
);
// print_r($ arr);出口();
$ this-> db-> insert('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\"> 
< html xmlns =http://www.w3.org/1999/xhtml>
< head>
< meta http-equiv =Content-Typecontent =text / html; charset = utf-8/>
< title> user< / title>
< / head>

< body>

< a href =<?= base_url();?> user / user / add> Add New< / a>
< table border =1cellpadding =5cellspacing =0>
< tr>
< td>否< / td>
< td>用户名< / td>
< td>性别< / td>
< td>地址< / td>
< td>操作< / td>
< / tr>
<?php / *?> <?php print_r($ user); ?><?php * /?>
<?php
$ n = 1;
foreach($ user as $ row):
$ gender =($ row-> gender == 1)?'male':'Female';

?>
< tr>
< td><?= $ n?>< / td>
< td><?= $ row-> username; ?>< / TD>
< td><?= $ gender; ?>< / TD>
< td><?= $ row->地址; ?>< / TD>
< td>
< a href =#>编辑< / a>
< a href =#>删除< / a>
< / td>
< / tr>
<?php endforeach; ?>
< / table>

< / body>
< / html>







user_view_add.php



<?= form_open('user / user / submit'); ?> 
< table cellpadding =5border =0>
< tr>
< td>用户名< / td>
< td><?= form_input('txtusername'); ?>< / TD>
< / tr>
< tr>
< td>性别< / td>
< td><?= form_dropdown('slogender',array('1'=>'男','2'=>'女')); ?>< / TD>
< / tr>
< tr>
< td>地址< / td>
< td><?= form_textarea('txtaddress'); ?>< / TD>
< / tr>
< tr>
< td>< / td>
< td><?= form_submit('btnsubmit','保存'); ?>< / TD>
< / tr>

< / table>

<?= form_close(); ?>







错误:添加新功能不起作用....



我尝试了什么:



错误:

< br $>


找不到对象!



在此服务器上找不到请求的URL。引用页面上的链接似乎是错误的或过时的。请告知该页面的作者有关错误。



如果您认为这是服务器错误,请联系网站管理员。

错误404

127.0.0.1

Apache / 2.4.29(Win32)OpenSSL / 1.1.0g PHP / 7.2.2

解决方案
这 - >负载>模型( '用户/ user_model', 'M');
}

函数index(){


data ['user'] =


this->间 - > GET_USER();

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();
	}
	
}




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/');
		}
	}

}

?>



user_view.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>user</title>
</head>

<body>

<a href="<?= base_url(); ?>user/user/add">Add New</a>
<table border="1" cellpadding="5" cellspacing="0">
	<tr>
    	<td>No</td>
        <td>Username</td>
        <td>Gender</td>
        <td>Address</td>
        <td>Action</td>
    </tr>
   <?php /*?> <?php print_r($user); ?><?php */?>
    <?php 
	$n=1;
	foreach($user as $row):
	$gender = ($row->gender == 1)?'Male':'Female';
	 
	?>
    <tr>
    	<td><?= $n ?></td>
        <td><?= $row->username; ?></td>
        <td><?= $gender; ?></td>
        <td><?= $row->address; ?></td>
        <td>
        <a href="#">Edit</a>
        <a href="#">Delete</a>
        </td>
    </tr>
    <?php endforeach; ?>
</table>

</body>
</html>




user_view_add.php

<?= form_open('user/user/submit'); ?>
	<table cellpadding="5" border="0">
    	<tr>
        	<td>Username</td>
            <td><?= form_input('txtusername'); ?></td>
        </tr>
        <tr>
        	<td>gender</td>
            <td><?= form_dropdown('slogender', array('1'=>'Male', '2'=>'Female')); ?></td>
        </tr>
        <tr>
        	<td>Address</td>
            <td><?= form_textarea('txtaddress'); ?></td>
        </tr>
        <tr>
        	<td></td>
            <td><?= form_submit('btnsubmit', 'Save'); ?></td>
        </tr>
 
    </table>

<?= form_close(); ?>




error: add new function not work....

What I have tried:

error:


Object not found!

The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error.

If you think this is a server error, please contact the webmaster.
Error 404
127.0.0.1
Apache/2.4.29 (Win32) OpenSSL/1.1.0g PHP/7.2.2

解决方案

this->load->model('user/user_model','m'); } function index() {


data['user'] =


this->m->get_user();


这篇关于解决PHP codignitor对象未找到问题,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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