【问题标题】:Set dropdown input default value based on third parameter in Grocery CRUD根据 Grocery CRUD 中的第三个参数设置下拉输入默认值
【发布时间】:2012-11-28 23:35:30
【问题描述】:

下面的代码示例,

function product($parameter){

   $crud = new grocery_CRUD();
   ...
   $crud->callback_add_field('dropdown_field_name',array($this,'_add_field_callback'));
   ...
   $output = $crud->render();
}

我可以这样做吗?

function _add_field_callback($parameter){
   //load db model
   //call the result and return as dropdown input field with selected selection when value = $parameter 
}

【问题讨论】:

    标签: codeigniter drop-down-menu grocery-crud


    【解决方案1】:

    我已经在我的一个 Web 应用程序中实现了 Grocery Crud。

    查看“如何创建依赖下拉菜单”的链接

    http://demo.edynamics.co.za/grocery_crud/index.php/examples/customers_management/add

    【讨论】:

    • 我以前看过这个教程.. 这不是我想要的。但这对我以后的使用肯定是一个很好的指南。谢谢!
    【解决方案2】:

    实际上,使用控制器很容易做到这一点。例如,您可以简单地这样做:

    function product($parameter){
    
        $this->my_test_parameter = $parameter;
    
       $crud = new grocery_CRUD();
       ...
       $crud->callback_add_field('dropdown_field_name',array($this,'_add_field_callback'));
       ...
       $output = $crud->render();
    }
    

    还有回调:

    function _add_field_callback($parameter){
       //load db model
       //call the result and return as dropdown input field with selected selection when value = $parameter 
    
       $value = !empty($this->my_test_parameter) ? $this->my_test_parameter : '';
       ...
       //here you can also use the form_dropdown of codeigniter (http://ellislab.com/codeigniter/user-guide/helpers/form_helper.html)
    }   
    

    我知道您非常期待杂货店 CRUD 的默认值,因此我向 github https://github.com/scoumbourdis/grocery-crud/issues/138 添加了一个问题。这将提醒您必须修复此问题。

    【讨论】:

    • 谢谢约翰!你真是个负责任的开发者!你赢得了我的尊重!我唯一不确定的是为什么我们需要插入这个“$this->my_test_parameter = $parameter;”它可以在另一个函数中回调。
    • 嗯...谢谢:)。我使用 $this->my_test_parameter 的原因是没有其他方法可以将自定义变量传递给回调。 Grocery CRUD 尚不支持自定义参数,因此目前这是使用它的最佳方式。如果问题是我们可以在回调中调用“$this”,答案是肯定的,因为我们仍然在同一个控制器中
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-30
    • 2015-10-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多