我遇到的错误是"无法找到您指定的型号:设置" 这是我的设置模型,我的文件名也是设置。它在localhost中运行良好,但在我的服务器上传后显示错误。我该如何解决这个问题:网络链接:http://layakdesign.co.nf/
错误显示:"无法找到您指定的型号:设置"
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
Class Settings extends CI_Model
{
public function __construct()
{
parent::__construct();
}
public function get_settings($code)
{
CI::db()->where('code', $code);
$result = CI::db()->get('settings');
$return = [];
foreach($result->result() as $results)
{
$return[$results->setting_key] = $results->setting;
}
return $return;
}
/*
settings should be an array
array('setting_key'=>'setting')
$code is the item that is calling it
ex. any shipping settings have the code "shipping"
*/
public function save_settings($code, $values)
{
//get the settings first, this way, we can know if we need to update or insert settings
//we're going to create an array of keys for the requested code
$settings = $this->get_settings($code);
//loop through the settings and add each one as a new row
foreach($values as $key=>$value)
{
//if the key currently exists, update the setting
if(array_key_exists($key, $settings))
{
$update = array('setting'=>$value);
CI::db()->where('code', $code);
CI::db()->where('setting_key',$key);
CI::db()->update('settings', $update);
}
//if the key does not exist, add it
else
{
$insert = array('code'=>$code, 'setting_key'=>$key, 'setting'=>$value);
CI::db()->insert('settings', $insert);
}
}
}
//delete any settings having to do with this particular code
public function delete_settings($code)
{
CI::db()->where('code', $code);
CI::db()->delete('settings');
}
//this deletes a specific setting
public function delete_setting($code, $setting_key)
{
CI::db()->where('code', $code);
CI::db()->where('setting_key', $setting_key);
CI::db()->delete('settings');
}
}
答案 0 :(得分:0)
这是类名和文件名的问题,给类名和文件名
写小写字母class settings extends CI_Model
{
...
}
和文件名也是settings.php
答案 1 :(得分:0)
您可以尝试按照以下方式创建模型。
Settings_model.php
http://layakdesign.co.nf//application/models/settings_model.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Settings_model extends CI_Model
{
public function __construct()
{
parent::__construct();
}
...
}
?>
将模型加载到特定控制器文件中。
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Setting extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->model('settings_model');
}
}
?>
答案 2 :(得分:0)
如果您的模型文件名为settings.php 比编写像
这样的代码$this->load->model('settings');
无论你的文件名是什么,都必须在模型函数中使用decalre同名。