use proxy route.
example:
Route::get("/proxy/banner/{banner}/{size}", function($banner, $size){
// handler
});
so in view you have to call an image with http://yourdomain.com/proxy/banner/bannername/50
If you are performing logic in your view, you are doing it wrong :)
I agree with netorious. I wouldn't say it's wrong but I'd definitely not do it that way in a "V" based framework.
Until a better answer comes up: I'd probably put your function into a "library" area (make sure to link to the new directory) and then put the function call getBanner into the base controller (this way you'll have access to the function through out your app).
I'm sure there is a better way to do this though :(
What will this getBanner
method be doing? Will it be returning the URL to an image?
Create a Library, your own library to handle such things...
Class myLib {
public static function getBanner($url=''){
//do me a favor here.....
return $url;
}
}
register your class for a global call
Call it anywhere inside view
<?php echo myLib::getBanner('csdcsdc');?>
What I want to do is call the method getBanner($size) and it return a random banner of the appropriate size. It would return the url to the banner, the alt tag and whether or not its a follow link.
I've seen a bunch of different ways to do it, but Im searching for the best way. I dont want to rewrite this 6 months down the road. :) I like the idea of a library but I wonder if even thats too much code in the view.
What about a view composer? Would that be a solution? On some pages I will call 1 banner on some up to 4 or 5.
Alex
Okay if you're fetching more than 1 you'll need a separate class to handle it. I'd create a BannerGenerator
class or something to that effect and have it behave much the same way @codetrash has implemented it.
class BannerGenerator {
public function generate($size)
{
// Generate the URL to the random banner.
return $url;
}
}
Then pass an instance of it to your view.
return View::make('example')->with('banner', new BannerGenerator);
And in your view you can use the generate
method.
<img src="{{ $banner->generate(1920) }}" />
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community