Php codeigniter不会显示我的producten表中的任何内容
谁能帮我看看吗 型号: 控制器: 视图:Php codeigniter不会显示我的producten表中的任何内容,php,database,codeigniter,echo,Php,Database,Codeigniter,Echo,谁能帮我看看吗 型号: 控制器: 视图: 加载数据库时,正确的表producten中有1行。我只是不知道该怎么办。有人能帮我解决这个问题吗?请至少找出问题所在。你发布M+C+V的事实表明你没有做出任何努力。提出一个更具体的问题 检查是否执行了正确的文件和行,例如:echo,数据是否从数据库var\u dump/print\r/echo加载,等等。。。真正地调试101…Afaik您必须调用模型product\u model.php,在控制器product\u model中调用它,并用大写字母p调用
加载数据库时,正确的表producten中有1行。我只是不知道该怎么办。有人能帮我解决这个问题吗?请至少找出问题所在。你发布M+C+V的事实表明你没有做出任何努力。提出一个更具体的问题
检查是否执行了正确的文件和行,例如:echo,数据是否从数据库var\u dump/print\r/echo加载,等等。。。真正地调试101…Afaik您必须调用模型product\u model.php,在控制器product\u model中调用它,并用大写字母p调用类product\u model 此外,CI不会自动连接到数据库,因此在加载时必须使用第三个参数指定它 因此: 以及: 像这样试试 模型
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Model_product extends CI_Model
{
public function getALL()
{
$results = $this->db->get('producten');
return $results->result_array();
}
}
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Welcome extends CI_Controller
{
public function index()
{
$this->load->model('Model_product');
$data['products'] = $this->Model_product->getALL();
$this->load->view('header');
$this->load->view('welcome_message', $data);
$this->load->view('footer');
}
}
<table class="table">
<thead>
<th>Naam</th>
<th>Beschrijving</th>
<th>Prijs</th>
<th>Vooraad</th>
<th>Categorie</th>
</thead>
<tbody>
<?php foreach ($products as $product) { ?>
<tr>
<td><?php echo $product['naam']; ?></td>
<td><?php echo $product['beschrijving']; ?></td>
<td><?php echo $product['prijs']; ?></td>
<td><?php echo $product['producten_op_voorraad']; ?></td>
<td><?php echo $product['categorie_naam']; ?></td>
</tr>
<?php } ?>
</tbody>
</table>
class Product_model extends CI_Model
$this->load->model('product_model', '', TRUE);
$data['products'] = $this->product_model->getALL();
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Model_product extends CI_Model
{
function __construct()
{
// Initialization of class
parent::__construct();
}
public function getALL()
{
$results = $this->db->get('producten');
return $results->result_array();
}
}
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Welcome extends CI_Controller
{
function __construct()
{
// Initialization of class
parent::__construct();
$this->load->model('model_product');
}
public function index()
{
$data['products'] = $this->model_product->getALL();
$this->load->view('header');
$this->load->view('welcome_message', $data);
$this->load->view('footer');
}
}
$autoload['libraries'] = array('database');