【问题标题】:Check grocery crud state检查杂货杂货状态
【发布时间】:2013-09-25 07:37:56
【问题描述】:

如果我正在呈现添加表单或只是一个视图,我想从控制器中检查。我想做这样的事情..

public function clients()
{
    try{

        if ($_SERVER["REQUEST_URI"] == "/data/clients")
        {
            $data['client'] = $this->db->query("select * from clients");
            $this->load->view('cview/client',$data);
        }
        else 
        {

            $crud = new grocery_CRUD();

            //$crud->set_theme('datatables');
            $crud->set_table('clients');
            $crud->set_subject('Clients');
            crud->required_fields('city');
            //$crud->columns('city','country','phone','addressLine1','postalCode');

            $output = $crud->render();

            $this->load->view('/crud/users',$output);
        }
    }catch(Exception $e){
        show_error($e->getMessage().' --- '. $e->getTraceAsString());
    }       
}

这会很好用,除非我使用的是 iframe,如果 url 没有改变,这将不起作用:P

【问题讨论】:

    标签: codeigniter grocery-crud


    【解决方案1】:
    $state = $this->grocery_crud->getState();
    

    这将得到它所处的状态。

            if (($state == "list" || $state == "success"))  
            {
    
                $data['client'] = $this->db->query("select * from clients");
                $this->load->view('cview/client',$data);
            }
            else 
            {
    
                $crud = new grocery_CRUD();
    
                //$crud->set_theme('datatables');
                $crud->set_table('clients');
                $crud->set_subject('Clients');
                $crud->required_fields('city','phone');
    
    
                //$crud->columns('city','country','phone','addressLine1','postalCode');
    
                $output = $crud->render();
    
                $this->load->view('/crud/users',$output);
            }
    

    在上面的示例中,“列表”将作用于取消按钮,而“成功”作用于添加屏幕或编辑屏幕上的保存和更新按钮。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-30
      • 1970-01-01
      相关资源
      最近更新 更多