To register a route, I specify the route in web.php in following way,
Route::get($uri, $callback)->name($name);
Is there any way to do this without any specific callback function?
I am building a laravel website but some portion are made with perl. I need to submit a form to a url where the perl code takes over. However, as the form is used in many places I want to use the $name part as form action inside my front end codes.
Essentially what I want is something like this,
Route::get('cgi-bin/route_to_perl_program.cgi', "DO NOTHING. LET PERL DO IT JOB")->name($url_name);
If you not to define any $callback function,there is no need to define a route in web.php. As you want to use route('name') to produce that url in all your blade file,there is an alternative. You need to add this line of code in your config/app.php as follows:
perl_url => 'cgi-bin/route_to_perl_program.cgi',
And use them in your blade like as
link text
This is not your answer,this might be a solution of your specific
need.
In your $callback function to run a command to execute your perl file and get back the output and return that output as a response.,e.g:
.....
$yourPerlOutPut = exec('perl ~/your/path/yourfile.pl');
return response($yourPerlOutPut);
exec() executes the given command.
You can put your route_to_perl_program.cgi file in public folder and access yourdomain.com/route_to_perl_program.cgi. It will run. You need not put it the route.
Or try something like the following
Route::get('cgi-bin/route_to_perl_program.cgi', function(){
exec('cgi-bin/route_to_perl_program.cgi');
})->name($url_name);
Related
Look at the image. I create changeName function inside the controller but it does not work.
My route :
Route::resource('products','ProductController');
why?
I tried to check all the syntax and it is correct.
By the first image you posted I suppose you mean it doesn't appear on the routes, is that right? If so, it's because you need to define the route on the the routes/web.php file. For example like that :
Route::get('/changeName', 'ProductController#changeName');
So in one of my views I am generating a redirect()->back()->with() command to send the user back to a previous page.
<button>Go Back</button>
the issue I run into is that it does not provide me with the url. This is what I get.
http://localhost:8888/pp/public/HTTP/1.0%20302%20FoundCache-Control:%20no-cacheDate:%20%20%20%20%20%20%20%20
%20%20Tue,%2024%20Nov%202015%2022:23:12%20GMTLocation:%20%20%20%20%20%20http://localhost:8888/pp/public/task/matching/response/house%3C!DOCTYPE%20html%3E%3Chtml%3E%20%20%20%20%3Chead%3E%20%20%20%20%20%20%20%20%3Cmeta%20charset=%22UTF-8%22%20/%3E%20%20%20%20%20%20%20%20%3Cmeta%20http-equiv=%22refresh%22%20content=%221;url=http://localhost:8888/pp/public/task/matching/response/house%22%20/%3
E%20%20%20%20%20%20%20%20%3Ctitle%3ERedirecting%20to%20http://localhost:8888/pp/public/task/matching/response/house%3C/title%3E%20%20%20%20%3C/head%3E%20%20%20%20%3Cbody%3E%20%20%20%20%20%20%20%20Redirecting%20to%20%3Ca%20href=%22http://localhost:8888/pp/public/task/matching/response/house%22%3Ehttp://localhost:8888/pp/public/task/matching/response/house%3C/a%3E.%20%20%20%20%3C/body%3E%3C/html%3E
So I'm thinking I am using the function wrong but how can I simply get a back() url to work?
What you probably want to use is URL::previous().
Go Back
The redirect()->back() method actually calls the URL::previous() method to create the RedirectResponse.
redirect() does generate a URL. It returns an instance of Illuminate\Routing\Redirector. It's meant for use within a Controller Method or a Route Closure.
You want the route() helper method
$url = route('routeName');
Actually redirect() cannot be used after printing any output, it will not work.
If you want the link to go back. Just use simple JS script, as described here.
Try using
{{ Request::referrer() }}
you can achieve the same by using just PHP (but I prefer the Laravel's syntax since it's more readable and clean :
$_SERVER["HTTP_REFERER"]
I have created a new module in ZF2 named 'HelloWorld'. What I am trying to do is, simply printing HelloWorld when I click on the link 'HelloWorld':
I want to generate this link(http://mayukh.my.phpcloud.com/zf2test/HelloWorld/) by using this:
$this->url('HelloWorld', array('action' => 'index'))
But it is showing the error like this:
http://mayukh.my.phpcloud.com/zf2test/
Please suggest how to avoid this error..
This is perhaps related to one of ZF2’s “features.” It seems that if you use ZF2 functions to construct your links, the function will drop out any segment that matches the default value you have named in your router script. See How to write the ZF2 router script to allow parameters on the default action.
Temporarily change or remove the defaults from your router script and see if that doesn’t solve your issue. If it does, you might have to either reconsider the scheme for your router scripts or code your links without ZF2’s url function.
I have am using Laravel and I am trying to call a single php file via the browser, which is
located in my app path.
I have setup a Route::get to a function HomeController#index
function index(){
include(app_path().'/myphpfile.php');
}
And gets called when doing http://localhost:8888/home/index
This is how I call it atm.
The Problem is my file accepts furthe parameters, which are
processed inside my php file like:
http://localhost:8888/myphpfile.php/user/hello1
or
http://localhost:8888/myphpfile.php/user/hello1/default
So I tried to use Route::any.
It is not working. Can I somehow just tell Laravel to pick up the php file like I mentioned above? Other way then using include?
I don´t want to put this file into the public folder.
Something like wildcard routing.
Thank you for your help.
I wanted the functionalities of view files to run in controller file also.
For example, I wanted $this->escapeHtml() which runs in view file alone to run in controller through some means like $this->...->escapeHtml()
Is this possible? Kindly help.
You need to get the ViewHelperManager and extract the EscapeHtml helper. This is a one example how to do it from the controller:
$viewHelperManager = $this->getServiceLocator()->get('ViewHelperManager');
$escapeHtml = $viewHelperManager->get('escapeHtml'); // $escapeHtml can be called as function because of its __invoke method
$escapedVal = $escapeHtml('string');
Note that it is recommended to escape and display the output in the view scripts and not in the controller.