杂货crud与phil外科医生模板

时间:2013-11-02 16:54:07

标签: php grocery-crud

我有一个问题如何使用杂货crud与phils模板库这里是我的代码控制器

public function user_management() { 
    $crud = new grocery_CRUD(); 
    $crud->set_subject('User'); 
    $output = $crud->render(); 
    $this->template->set_layout('blog');
    $this->template->set('output', $output); 
    $this->template->title('home', 'Grocery-Crud'); 
    $this->template->build('grocery'); 
}

这是我的观点

<?php foreach($css_files as $file): ?>
<?php endforeach; ?> 
<?php foreach($js_files as $file): ?> 
<?php endforeach; ?>
<?php echo $output; ?>

我遇到了像

这样的错误
 A PHP Error was encountered Severity: Notice Message: Undefined variable: css_files Filename: views/grocery.php Line Number: 2 A PHP Error was encountered Severity: Warning Message: Invalid argument supplied for foreach() Filename: views/grocery.php Line Number: 2 A PHP Error was encountered Severity: Notice Message: Undefined variable: js_files Filename: views/grocery.php Line Number: 5 A PHP Error was encountered Severity: Warning Message: Invalid argument supplied for foreach() Filename: views/grocery.php Line Number: 5 A PHP Error was encountered Severity: 4096 Message: Object of class stdClass could not be converted to string Filename: views/grocery.php Line Number: 10

请帮助

1 个答案:

答案 0 :(得分:0)

控制器

  public function user_management() {
$crud = new grocery_CRUD();
$crud->set_table('user');
$crud->set_subject('User');
$output = $crud->render();
$this->template->set_layout('blog');
$this->template->set('output', (array) $output);
$this->template->title('home', 'Grocery-Crud');
$this->template->build('grocery');
}

在视图中

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

<div>
    <?php echo $output['output']; ?>
</div>