In which Class are these 'blade functions' startSection() and stopSection()? - laravel

When you open the cached view inside storage/framework/views/, there are rendered blade views and I can't find these functions:
$__env->startSection('content');
and
$__env->stopSection();
It's probably made with call_user_func() so you can't get to it just by clicking Ctrl+Click, this needs to be answered by someone who really knows the guts of Laravel :)

You can find these methods in the traits used on the Illuminate\View\Factory class.
https://github.com/laravel/framework/blob/5.8/src/Illuminate/View/Factory.php#L17-L23
This specific method is actually on the Illuminate\Views\Concerns\ManagesLayouts trait.
https://github.com/laravel/framework/blob/5.8/src/Illuminate/View/Concerns/ManagesLayouts.php
Also, in the constructor of that class you will see that $__env is shared with the view.
https://github.com/laravel/framework/blob/5.8/src/Illuminate/View/Factory.php#L99

Related

What's the alternative to Symfony render(controller) in Laravel

In Symfony I am using widget-like behaviour by calling controller method from twig
{{ render(controller(
'App\\Controller\\ArticleController::recentArticles',
{ 'max': 3 }
)) }}
It does the logic and returns another twig template, which is embeded here.
How in the Laravel do people solve this? I need this for displaying menu, responsive menu, product lists, breadcrumbs etc.
I have read about View composers and studied the documentation - but there's mentioned only how you can inject some variables into the view.
The same with using #inject() in blade.
But I want standalone widget (with own logic, data fetching...) with custom blade template embeded/inserted in any place I call them from.
Thanks for an advice.
Btw. It doesn't need to be Controller that I call, it could be a Service object. But the point is the same. I was personally calling these objects like _WidgetController (beginning with underscore - to tell me, they are not fully qualified views, but components/widgets). But I placed them into my Controllers folder.

Show specific presenter instance to flex panel gwt mvp

I'm still learning GWT, yet already have to face some kind of challenge for a work I have to do. Can't show any specific code so I'll try to explain it well.
Here's the situation: A certain class "Navigator" creates and save the Presenter instances of my architecture to allow reusing them. There is a method show() inside that same class that actually displays the view related but that system only works full screen by calling RootPanel.get().
What i'd like to do is showing that presenter instance's view inside of a flex panel element declared in a class myView (related to a class myPresenter) that basically uses Flex Panel to structure it's content.
To make it maybe more clear:
class myView{
...
flexPanel.setWidget(firstWIdget)
flexPanel.setWidget(secondWidget) //secondWidget to be replaced by a "thirdWidget"
...
}
I'd like the secondWidget to be replaced by another one, let's call it thirdWidget, that consists of a specific presenter instance's view.
To resume, I'd like my presenter instance's view to not go full screen but only occupy a certain area of the screen.
The displaying is managed almost entirely programmatically, means very limited use of css files and no use at all of xml ui files.
How can I manage this ?
Thanks
Use a SimplePanel as a container for your views returned by your Navigation class instead of adding them directly to root panel, and use that instance of SimplePanel where ever you want.

Simple way to call a method on the View (Code Behind)

I have a small issue I was hoping somebody could help me with. I have to call the NavigationService.RemoveBackEntry() on two of my views due to the way I have my first run wizard set up.
This method needs to be called on the view (in the codebehind) as far as I am aware and cannot be called in my view models.
I was wondering what would be the easiest, cleanest way to call a RemoveLastNavEntry() from the ViewModel if the method lives on the view.
Rob has said it is a feature he will build into the navigation service at some point but until then I need to implement this as a minor hack.
While this truely is a task for the view, you can, if you really want to, call it from the ViewModel, as a static call.
(App.Current.RootVisual as PhoneApplicationFrame).RemoveBackEntry()
See PhoneApplicationFrame.RemoveBackEntry Method for documentation.

Symfony 1.4 and pjax (ajax pushstate)?

symfony: http://www.symfony-project.org
pjax: https://github.com/defunkt/jquery-pjax
Hi all,
I'm trying to use pjax in symfony in order to speed up our website (we will be able to keep header and footer static most of the time, and also avoid reloading lots of css/js and other files).
I have no problem with ajax or symfony, but I want to know if there is a better way:
Is it a good idea to use postExecute to return the html code back right away without sf going to the template at all
If so, can I somehow write this only once for all modules? I imagine that I can do:
mySfActions extends sfActions
moduleActions extends mySfActions
I wonder if there is a better way?
3. Is there a way to get the current layout name (defined in the module's view.yml) within the controller/action?
Question 1: Don't use post-execute like that. If you need to return html from an ajax call in your action then your action should return like this:
return $this->renderText("<p>Your html result.</p>");
This will skip the template call.
Question 2: That is correct. You have written the best way to write a function once and have it available to all module actions.
There is nothing to do.
When calling an action via XmlHttpRequest, symfony automaticaly skip the Layout render, and only return the module render.
You need to put all your "static" assets and html in your layout and that's all.
Thank you all for helping me, all your answers were helpful and pointed me to the right direction. I wanted to vote for both answers but since I can only accept one, I accepted the very first answer.
Anyhow, here is what I did:
First, I extended the sfActions class so I don't have to do add preExecute on every module:
<?php
class mySfActions extends sfActions{
public function preExecute(){
$request = $this->getRequest();
if ($request->getParameter('_pjax')) {
$this->setLayout(false);
}
}
}
Then of course each of my module action class must extend this new class.
Inside my individual template I have something like this:
<?php if($sf_request->getParameter('_pjax')):?>
<script type="text/javascript" src="/js/question_list.js"></script>
<?php endif;?>
This currently seems to work quite well for me, I'm enjoy the incredible loading speed when pushstate is supported, and still able to fallback when it is not (on the dumb IE for example)

Where should I implement this? View or ViewController?

I have to implement an Form View, or in other words: A class that is used to put a complex input form on the screen.
The Form is built up of FormComponents. There is an addFormComponent() Method to compose the form with these. And then, the form has an isValid() Method which will go through all the FormComponents and check their associated FormValidators.
For sure this thing has a lot of "intelligence", but most of this is just a call to some other class. For example the isValid() method does cool stuff, but it really only calls the isValid() methods of the FormComponents which are registered in an array. Nothing too fancy.
Well, that beeing said, must I make a fat FormViewController for this, or is an View just fine?
My understanding of these is, that a ViewController is used when there's some big logic involved. In this case, the Form View has a template which will simply iterate over the FormComponents and include them. Each FormComponent has it's own template in turn and does it's own stuff.
I've always been struggling with ViewController and View and I think I'll keep on doing that until I get a nice R.I.P. brick... but maybe someone can clear this up a little bit ;-)
The purist in me is saying that this belongs in a ViewController. I guess maybe it would depend on the framework you are using. For example, this type of setup would be very easily implemented in a Spring Controller object. It sounds like creating a controller in your case would be a lot of extra work.
Nothing is ever set in stone. You can implement in the View for now and if this turns out to be a huge burdon, move it to a Controller class. Knowing when to refactor is the difficult part.

Resources