I want to create a URL using volt (Phalcon).
I have tried:
{{ url("order/view/", ["id" :order.id]) }}
However that produces a URL like:
http://localhost/gateway-new/order/view/?id=7
Whereas I would like the url to look like:
http://localhost/gateway-new/order/view/id/7
Any idea how to do this correctly?
if you have a route defined like
$router->add('order/view/id/:int', array(
'controller' => 'order',
'action' => 'view',
'id' => 1))->setName('order-view');
you could use
{{ url(['for': 'order-view', 'id': order.id]) }}
{{ url("order/view/id/" ~ order.id) }}
Related
stuck with this error any help would be much appreciated. The error I'm getting is below:
Action App\Http\Controllers\PostsController#destroy not defined. (View: C:\xampp\htdocs\lsapp\resources\views\posts\show.blade.php)
I do have the "destroy" method in the PostsController and using the latest vision of Laravel.
{!!Form::open(['action' => ['PostsController#destroy', $post->id], 'method' => 'POST', 'class' => 'pull-right'])!!}
{{Form::hidden('_method', 'DELETE')}}
{{Form::submit('Delete', ['class' => 'btn btn-danger'])}}
{!!Form::close()!!}
Try this.
I changed ACTION to URL.
{!!Form::open(['url' => ['posts', $post->id], 'method' => 'POST', 'class' => 'pull-right'])!!}
{{Form::hidden('_method', 'DELETE')}}
{{Form::submit('Delete', ['class' => 'btn btn-danger'])}}
{!!Form::close()!!}
Syntax gets changing in laravel versions frequently. So always check your version.
Right now i think you might be using Laravel version 5.4.36 or something.
So I think try by changing 'ACTION' to 'URL' as below.
{!!Form::open(['url' => ['PostsController#destroy', $post->id], 'method' => 'POST', 'class' => 'pull-right'])!!}
{{Form::hidden('_method', 'DELETE')}}
{{Form::submit('Delete', ['class' => 'btn btn-danger'])}}
{!!Form::close()!!}
Your action method is fine the way you wrote it. That error literally means that you don't have a controller named PostsController#destroy.
Just run:
php artisan route:list
If the controller exist, the name column would give you the prefix and method Post.destroy and in the same row the action column would give you the controller name PostsController#destroy. Obviously if those two conditions are not there; you get the error:
Action App\Http\Controllers\PostsController#destroy not defined.
You can try to use the action helper function like this action('WelcomeController#log_in') or you can just set the action to a route that provides you the controller.
You've missed a step.
Think back to what the action attribute in an html form looks like:
action="{{ you put a url here, not a controller action }}"
Then consider your routes file, where you should add whatever route you decide to reference within {{ }} above, and map it to your controller action in the routes file.
I'd advise doing this without using Form::, then you will understand it better (and it's no more complicated).
juste you need to change method form inside your form to delete like this :
{!!Form::open(['action' => ['PostsController#destroy', $post->id], 'method' => 'DELETE', 'class' => 'pull-right'])!!}
{{Form::hidden('_method', 'DELETE')}}
{{Form::submit('Delete', ['class' => 'btn btn-danger'])}}
{!!Form::close()!!}
in Laravel 8 full description of the route is required as follows:
{!!Form::open(['action' => ['App\Http\Controllers\PostsController#destroy', $post->id],
'method' => 'POST', 'class' => 'float-right'])!!}
so I have some php variables, some are form an array. I can print them like this
echo $arr->title;
echo $arr->date;
echo $xml;
echo $cover;
I am using twig. I think I need to combine specific php variables into one array(say book) so I can render my twig template with
echo $template->render(['book' => $book]);
then in my twig template be able to use
{{ title }}
{{ date }}
{{ xml }}
{{ cover }}
any tips on how to achieve this would be greatly appreciated .
Just create the array for your needs:
$viewData = [
'book' => [
'title' => $arr->title,
'date' => $arr->date,
'xml' => $xml,
'cover' => $cover,
]
];
echo $template->render($viewData);
Template
{{ book.title }}
{{ book.date }}
{{ book.xml }}
{{ book.cover }}
If you want to be able to use the data in your twig template like this:
{{ title }}
{{ date }}
{{ xml }}
{{ cover }}
then you need to pass on the data to the view like that:
echo $template->render([
'title' => $arr->title,
'date' => $arr->date,
'xml' => $xml,
'cover' => $cover,
]);
If I have an array passed to twig like this
$values = [
'title'=>'Title of Page',
'subsection_a'=>[
'title'=>'Title of Subsection'
],
];
What I'd want to do is for a specific section in my template, use 'subsection_a' as the base so when I do {{ title }} it says "Title of Subsection" rather than "Title of Page"
I'm very unfamiliar with Twig, and I'm testing it as a replacement for a template engine I threw together for a project.
If your dividing the main proportion of your templates in subtemplate you can do it with the keyword with:
controller.php
echo $twig->render('main.twig, [
'title' => 'parent',
'foo' => 'bar',
'bar' => 'foo',
'child' => [
'title' => 'Child',
'foo' => 'Foobar',
]
]);
main.twig
<h1>{{ title }}</h1>
<p>{{ foo }}</p>
{% include "child.twig" with child %}
child.twig
<h2>{{ title }}</h2>
<p>{{ foo }}</p>
twigfiddle
There is no Twig-way of achieving this.
If it's just for ease of use, you could set a short variable, such as
{% set sub = subsection_a %}
This would allow you to write {{ sub.title }}.
You could create a new array with twig, merge the specific subsection, but in your case, it would make managing the code more difficult, you could have duplicate and it might not be worth the trouble.
I have defined a resourceful route like this:
Route::resource('user/info/experience', 'ExperienceController');
And the following is what i have used in my form:
{!! Form::open([
'route'=>'user.info.experience.store',
'method' => 'post',
]
) !!}
Now it's giving me the
Route [user.info.experience] not defined
What am I doing wrong?
There was no problem with the route definition or in from. The problem was that there was another call to user.info.experience in my view which didn't exist. So I corrected that call and the error is gone.
try this:
Routes
Route::resource('user/info/experience', 'ExperienceController');
Form
{!! Form::open([
'route'=>'user/info/experience',
'method' => 'post',
]
) !!}
or use alias:
Routes
Route::post('user/info/experience', array('as' => 'experience', 'uses' => 'ExperienceController#functionName'));
Form
{!! Form::open([
'route'=>'experience',
'method' => 'post',
]
) !!}
try Route::resource('user.info.experience', 'ExperienceController');
I have this basic form:
{{ Form::open(array('url' => URL::route('post-account-changeProfilePic'), 'files' => true, ))}}
{{ Form::file('photo') }}
<br />
{{ Form::submit('Regístrarme', array("class" => "button expand round")) }}
{{ Form::close() }}
My Route is inside of 2 groups: before=>Auth and before=>csrf
Route::post('/accont/changeProfilePic', array(
'as' => 'post-account-changeProfilePic',
'uses' => 'CallCenterController#postChangeProfilePic'
));
In my controller, I just dump my variable to see what I got:
public function postChangeProfilePic(){
$input = Input::all();
var_dump($input);
}
These are the errors I am getting:
1- Illuminate \ Session \ TokenMismatchException.
This because of the csrf filter, but since I am using blade, the token is actually there. Also, if I remove the name attribute from the file input, this error will not be displayed.
So far, I decided to place the route outside of the csrf filter until I understand what is going on.
2- After placing the route out of the csrf filter, and try to display all the inputs, I get a null array.
I decided to add a new text field and if I don't select a photo/pic and only send the form like that, it'll dump on screen all the inputs, but of course, the file is empty/null.
Any idea about what I am doing wrong?
In your form try changing this to
array('before' => 'csrf'), function()
{{ Form::open(array('url' => URL::route('post-account-changeProfilePic'), 'before' => 'csrf'), 'files' => true, ))}}
The csrf token should be there by default since you are doing a POST request, so not sure where there is an issue there.
http://laravel.com/docs/4.2/html#csrf-protection
for the input try
public function postChangeProfilePic(){
if (Input::hasFile('photo'))
{
$input= Input::file('photo');
var_dump($input);
}
}
http://laravel.com/docs/4.2/requests#files
Okay I think it could be this
change
{{ Form::open(array('url' => URL::route('post-account-changeProfilePic'),
'files' => true, ))}}
to
{{ Form::open(array('route' => 'post-account-changeProfilePic',
'files' => true )) }}
I don't think you need the ',' at the end of the true either.