【问题标题】:Codeigniter display 2 crud grocery table to 1 tableCodeigniter 显示 2 张杂货杂货桌到 1 张桌子
【发布时间】:2016-10-22 18:51:53
【问题描述】:

这里有两张表。

我要1张桌子

我是 Codeigniter 和杂货店的新手, 我的 Golongan display 2 table,我不知道如何解决它

控制器>Golongan.php

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

class Golongan extends MY_Controller {

    function __construct()
    {
        parent::__construct();
        $this->load->database();
        $this->load->helper('url');
        $this->load->library('grocery_CRUD');
    }
    public function index()
    {
        $crud = new grocery_CRUD();
        $crud->set_table('golongan');
        $crud->columns('idgol', 'jabatan', 'fasilitas');

        $crud->unset_delete();
        $crud->unset_edit();
        $crud->unset_add();
        $output = $crud->render();

        $this->load->view('golongan',$output);
        $this->render('golongan','full_width'); // (full_width) it must for load template
        }
}

// 如果我删除了 $this->load->view('golongan',$output);杂货杂货 不出现,

// 如果我删除了 $this->render('golongan','full_width');模板 没有出现

//如果我都加了,有2个表,我想把它变成1个 表

查看>golongan.php

<?php 
foreach($css_files as $file): ?>
<link type="text/css" rel="stylesheet" href="<?php echo $file; ?>" />
<?php endforeach; ?>
<?php foreach($js_files as $file): ?>
<script src="<?php echo $file; ?>"></script>
<?php endforeach; ?>

<?php echo $output; ?>

【问题讨论】:

  • 嗨,请试试这个:$output = $crud->render(); $this->load->view('golongan',$output);这是杂货杂货的默认设置。如果默认配置工作正常,则存在一些人为错误。谢谢
  • 是的,默认杂货店工作正常,但没有出现模板,这意味着我需要渲染(全宽)
  • 请把最后一行注释一下:$this->render('golongan','full_width');

标签: php codeigniter grocery-crud


【解决方案1】:

如果你想在同一个视图中显示 2 个表...将每个输出对象传递给视图

控制器

  $crud = new grocery_CRUD();
    $crud->set_table('Table2');
    $crud->columns('idgol', 'jabatan', 'fasilitas');

    $crud->unset_delete();
    $crud->unset_edit();
    $crud->unset_add();
    $data['output'] = $crud->render();

 $crud = new grocery_CRUD();
    $crud->set_table('Table_2');
    $data['output_2'] = $crud->render();

    $this->load->view('your_view',$data);     

在视图中

       <?php 
foreach($output->css_files as $output->file): ?>
<link type="text/css" rel="stylesheet" href="<?php echo $output->file; ?>" />
<?php endforeach; ?>
<?php foreach($output->js_files as $output->file): ?>
<script src="<?php echo $file; ?>"></script>
<?php endforeach; ?>

<?php echo $output->output; ?>
<?php echo $output_2->output; ?>

【讨论】:

  • 将 $$output 固定为 $output
  • 你好,我想他想显示一个一个表,但是两个表意外出现,因为两次渲染......问题有点混乱。
【解决方案2】:

Hy fahmi,试试这个:

public function index()
    {
        $crud = new grocery_CRUD();
        $crud->set_table('golongan');
        $crud->columns('idgol', 'jabatan', 'fasilitas');

        $crud->unset_delete();
        $crud->unset_edit();
        $crud->unset_add();
        $output = $crud->render();

		$view = 'golongan';
		$this->outputview->output_admin($view, $output);
        }

【讨论】:

  • 没有渲染 "full_width" 表示要加载模板
【解决方案3】:

类 Golongan 扩展 MY_Controller {

function __construct()
{
    parent::__construct();
    $this->load->database();
    $this->load->helper('url');
    $this->load->library('grocery_CRUD');
}
public function index()
{
    $crud = new grocery_CRUD();
    $crud->set_table('golongan');
    $crud->columns('idgol', 'jabatan', 'fasilitas');

    $crud->unset_delete();
    $crud->unset_edit();
    $crud->unset_add();
    $output = $crud->render();


    }

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-30
    • 1970-01-01
    • 2014-05-13
    • 1970-01-01
    • 2012-05-23
    • 1970-01-01
    相关资源
    最近更新 更多