如果我正在渲染添加表单或只是视图,我想从控制器检查。我想做这样的事情..
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,否则这样做会很有效,如果网址没有变化,这不会有效:P
答案 0 :(得分:0)
$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);
}
在上面的示例中,“list”将用于取消按钮,“success”适用于添加屏幕或编辑屏幕上的保存和更新按钮。