{{ form_widget(form.category,{value:"3"}) }} //works!!
{{ form_widget(form.category,{value:'3'}) }} //works!!
{{ form_widget(form.category,{value:3}) }} // doesn't work !!
{{lastCatId}} // echos 3 !!!
{{ form_widget(form.category,{value:"lastCatId"}) }} //doesn't work ???
{{ form_widget(form.category,{value:'lastCatId'}) }} //doesn't work ???
I know after symfony 2.3. Value has to be quoted or double quoted. But I don't know why the variable doesnt work
never mind. I found the problem
{{ form_widget(form.category,{'value' : lastCatId|number_format }) }}
I had to cast it to int.
Related
I'm trying to display a translated word on the blade in a laravel application.
my language variable is "texts"
and I have the following on my blade
#foreach($permission as $value)
<li><label>{{ Form::checkbox('permission[]', $value->id, false, array('class' => 'name')) }}
{{ ('$value->name') }}</label></li>
<br/>
#endforeach
I'm trying to translate this
{{ ('$value->name') }}
This should give a result like, user-edit, user-view...
In my language file, I have the translated texts for those outputs.
I've tried this on my blade
{{ __('texts.$value->name') }}
But it just only printing
texts.$value->name
What is the correct way of translating this,
{{ ('$value->name') }}
You are using single quotes in {{ __('texts.$value->name') }}. Variables don't expand inside single quotes. Concatenate the two strings instead:
{ __('texts.' . $value->name) }}
I have defined route
Route::get('/edit-industry/{id}', 'Industries#edit')->name('admin.editIndustry');
And passing variable by
{{ route('admin.editIndustry', ['id'=>1]) }}
OR
{{ route('admin.editIndustry', [1]) }}
This is not working. How to pass variable here?
wow, why are wrong answers (or answers for questions which were not asked in this case) upvoted?
EkinOf is correct, you can do
{{ route('admin.editIndustry', 1) }}
Btw your first one works too and is necessary, if you have more than 1 parameter
{{ route('admin.editIndustry', ['id'=>1]) }}
{{ route('admin.editIndustry', ['id'=>1, 'something'=>42]) }}
If you have only one parameter you can do that :
{{ route('admin.editIndustry', 1) }}
Passing single parameter:
##Defining Route:##
Route::get('edit-industry/{id}', ['as' => 'admin.editIndustry', 'uses' => 'Industries#edit']);
##Calling Route:##
{{ route('admin.editIndustry',[$id]) }}
Passing multiple parameter:
##Defining Route:##
Route::get('edit-industry/{id}/{step}', ['as' => 'admin.editIndustry', 'uses' => 'Industries#edit']);
##Calling Route:##
{{ route('admin.editIndustry',[$id, $step]) }}
Simply try like this
View
{{URL::to('/edit-industry/1')}}
Route
Route::get('/edit-industry/{id}', 'Industries#edit')
Controller
public function edit($id){
// use $id here
}
Hope you understand.
Using generating URLs from Named Routes route():
{{ route('admin.editIndustry', 1) }}
Using URLs url():
{{url('/edit-industry', [1])}}
You can Directly pass with route name
{{ URL::to('/edit-industry/1') }}
I have been reading about form model binding https://laravelcollective.com/docs/5.0/html#form-model-binding
It's very cool to populate DB values in html form.
I tried like this and this works fantastic.
{{ Form::model($university,array('url' => admin_path('universities/edit'),'id' => 'add_university','name' =>'add_university','data-validate'=>"parsley")) }}
{{ Form::label('university_name', 'University name',array('class'=>'control-label')) }}
{{ Form::text('university_name')}}
{{Form::close()}}
But the problem is here, Cause i want to add more attributes in input like class SO i am using
{{ Form::label('university_name', 'University name',array('class'=>'control-label')) }}
{{ Form::text('university_name','',array('class' => 'form-control'))}}
If i leave blank valuecolumn then nothing populate in textbox and if i using like this
{{ Form::label('university_name', 'University name',array('class'=>'control-label')) }}
{{ Form::text('university_name',$university->university_name,array('class' => 'form-control'))}}
Then what is use of model binding.
Please explain.
Thanks
{{ Form::text('university_name','',array('class' => 'form-control'))}}
It should be:
{{ Form::text('university_name',null,array('class' => 'form-control'))}}
'' means the real string, not null.
thanks, mathielo, for helping me on grammar
I have a specific problem with concat of twig.
When I trying to concatenate dynamic variables showing the error.
Here is my code :
{% set i = 0 %}
{% set nbLignes = codeEvt.nb_lignes_~i %}
{% set nbLignesRef = codeEvt.nb_lignes_ref_~i %}
But I have this error message :
Method "nb_lignes_" for object "\DTO\SuiviJourFonc" does not exist in XXXXXXXXX.html.twig at line 211
I would like to take codeEvt.nb_lignes_0 , but i would like build a "for" for others variables like nb_lignes_1, nb_lignes_2 , nb_lignes_3 ...
How can i do this ?
attribute can be used to access a dynamic attribute of a variable:
The attribute function was added in Twig 1.2.
{{ attribute(object, method) }}
{{ attribute(object, method,arguments) }}
{{ attribute(array, item) }}
Try like this,
{{ attribute(codeEvt, 'nb_lignes_ref_' ~ i) }}
You can try the array-like notation:
{{ codeEvt['nb_lignes_ref_' ~ i] }}
Or even use string interpolation:
{{ codeEvt["nb_lignes_ref_#{i}"] }}
I have a problem and I can't resolve it, please help me. So I have my form :
{{ Form::open(array('url'=>'/administration/student/addMarks','method' => 'post')) }}
#foreach($aObjectsInGroupe as $object)
{{ Form::hidden('id_object[]',$object->id) }}
{{ Form::label($object->name) }}
{{ Form::select('note[]', $aMarks, null, array('class'=>'form-control')) }}
<br />
#endforeach
{{ Form::hidden('id',$aOneStudent['id']) }}
{{ Form::submit('Add mark',array('class'=>'btn btn-primary')) }}
{{ Form::close() }}
In my StudentController I have a method for get the mark from student_id and object_id:
public function getMarkByStudentAndObject($nIdStudent, $nIdObject){
$aMark = \Mark::where('student_id', '=', $nIdStudent)
->and('object_id', $nIdObject)
->get()
->toArray();
}
$aMarsks it's a table :
$aMarks = array(
'0'=>'0',
'1'=>'1',
'2'=>'2',
'3'=>'3',
'4'=>'4',
'5'=>'5',
'6'=>'6',
'7'=>'7',
'8'=>'8',
'9'=>'9',
'10'=>'10',
);
It's possible to call the method getMarkByStudentAndObject in :
{{ Form::select('note[]', $aMarks, null, array('class'=>'form-control')) }}
to get the selected value?
Help me please. Thx in advance.
maybe you need to do this:
<select name="note[]" class="form-control">
#foreach($aMarks as $key => $value)
<option value="{{ $key }}">{{ $value }}</option>
#endforeach
</select>
You should also check your Eloquent query, instead of ->and use another ->where
Try the lists() function of the Query Builder
\Mark::where('student_id', '=', $nIdStudent)
->and('object_id', $nIdObject)
->lists('column_1', 'column_2');
You then get the values of column_1 as the keys of the array and column_2 as the values.
http://laravel.com/docs/4.2/queries#selects
You should be able to directly call this from the Form::select. A call to
Mark::getMarkByStudentAndObject($aOneStudent['id'], $object->id)->note
would give you the Mark object and then you would need to get the note column which stores the value in the Mark object. Resulting in a call like this:
{{
Form::select(
'note[]',
$aMarks,
Mark::getMarkByStudentAndObject(
$aOneStudent['id'],
$object->id
)->note, array('class'=>'form-control')
)
}}
At the moment I can't verify if this is working because I have no possibility to test it but it should work as Blade is just a wrapper for PHP calls.