Is it possible somehow to add few my own methods to JModel / JModelLegacy without changing source code? For example from controller.
If you want to directly add it into JModel / JModelLegacy then no.
If you building a component then yes as you extend JControllerLegacy / JController when you build your component in the controller.php file. But that will be specific to your component of course. It can't be used by another component
Related
On my website i have to write a number of custom UI components and stays independently to the Controllers and Models, to generate views (In common some people call them UI-widgets).
i.e Creating re-usable "site-search" widget.
Currently, my approach is, I create an extended Component under the "Phalcon\Mvc\User\Component"
use Phalcon\Mvc\User\Component as Component;
class SiteSearch extends Component
{
function doSomething (){
//how to call a custom view for this component?
}
}
However, I am confused about how we can integrate a view for this extended "Component"? Any idea or different approach we can use?
You can use partials, and reuse it in places where needed.
https://docs.phalcon.io/4.0/en/views#partials
As mentioned in the title, I have different modules that I use in a template and I want to use a module's property in an other module. Is there a way to do it in Jahia 7 ?
Yes, it's possible. The correct way to do that is to include a fragment view of the other module into the main/calling module.
Example:
Delegating rendering (Employee definition/module needs to render a field/views from Company definition/module)
mynt_employee/html/employee.jsp
<h2>${currentNode.properties['jcr:title'].string}</h2>
<h3>Company</h3>
<template:module node="${currentNode.properties.company.node}" view="hidden.name" />
This code delegates the rendering of a company content to the company component
mynt_company/html/company.hidden.name.jsp - You just need to display the field that you want (here the title of Company):
${currentNode.properties['jcr:title'].string}
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
I'm using the securesocial plugin and use it as a module.
So my Structure is like:
project
|
|--app
|---|
|---|--views/main.scala.html
|--conf
|--logs
|--module
|---|--securesocial
|---|------|
|---|------|--app
|---|------|---|
|---|------|---|--views/main.scala.html
|---|------|---|--views/login.scala.html
My simple Question is, HOW can I overwrite the main.scala.html from my module/securesocial/app/views with my "main.scala.html"-view in my "app/views"-folder?!
I mean with "overwrite", that I can include the login view into the "#content"-variable of my main.scala.html, that normally would work like:
#main("My title test"){
<p class="note">
Try <em>guillaume##sample.com</em> with <em>test123</em> as password.
</p>
}
But with "#main" I can not access (and therefore overwrite) my "app/views/main.scala.html" out of the module folder.
SecureSocial renders views using a plugin that you can customize The default implementation is DefaultTemplatesPlugin that you can replace with your own to change the generated html.
To create custom pages and emails:
Create a new directory under views to place the custom templates for SecureSocial.
Create a new plugin that implements the TemplatesPlugin trait and renders those templates.
Edit the play.plugins file and replace DefaultPluginsTemplate with your own class.
You can see what methods you need to implement by looking at the TemplatesPlugin trait or in the documentation page: http://securesocial.ws/guide/views-customization.html.
Try giving it the exact package name for the view:
#views.html.main("My title test"){
...
}
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)