dongping9475 2014-03-18 13:16
浏览 23

laravel 4修改控制器内的输入值[重复]

This question already has an answer here:

Okay, this one is a bit tricky and unusual, but I need to do it for one of my project.

so I have 2 routes :

Route::get('table/edit',  array('uses'=>'CompanyController@editTable'));

Route::post('table/update',  array('uses'=>'CompanyController@editTableAction'));

Now the fields in the database table I'll be storing data are dynamic, So I must take advantage of the :

Input::all(); 

Method. There's a hidden input in my form

<input type="text" name="database_field_name_user_friendly" value="User Input Some Name" />

<input type="hidden" name="database_field_name" value="" />

Now, as you can see,

Input::get('database_field_name');

is empty. Is there a way I can set the value of this input box inside the controller? I need to process the value from another input field database_field_name_user_friendly . I'll run regex to make it a valid MySQL field name.

Any help will be much appreciated.

</div>
  • 写回答

1条回答 默认 最新

  • doujing2017 2014-03-18 13:24
    关注

    I got the solution just after posting the question :p

    Hope this helps someone else! Really very easy. Inside your controller

    Let's process the input

    $database_table_name = strtolower(Input::get('account_database_table_name'));
    //make alphaunermic
    $database_table_name = preg_replace("/[^a-z0-9_\s-]/", "", $database_table_name);
    //Clean multiple dashes or whitespaces
    $database_table_name = preg_replace("/[\s-]+/", " ", $database_table_name);
    //Convert whitespaces and underscore to dash
    $database_table_name = preg_replace("/[\s_]/", "_", $database_table_name);
    

    And then simply set the value! Using Laravel Input::merge method

     Input::merge(array('account_database_table_name'=>$database_table_name));
    

    Thanks!

    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分