Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 9 years ago.
Improve this question
i am trying to generate pdf using TCPDF and want to attach this PDF to an email,
and send it to various email addresses.
What is the right way to render twig file in Services?
Please take a look at this post, was helpful for me:
http://richsage.co.uk/2011/12/16/rendering-emails-with-twig-in-symfony2/
First, you need to add templating to your service
your_bundle.your_service_name:
class: your_project\your_bundle\Service\your_service
arguments: [#templating]
Then you need to add the templating service to your service constructor
private $templating;
function __construct($templating)
{
$this->templating = $templating;
}
After that you just need to call it in the function that handle the TCPDF rendering
function renderTCPDF()
{
$renderedTemplate = $this->templating->render('your_bundle:template_folder:twig_name', array(your_parameters));
}
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
So I was wondering the other day, where to put private methods, that do some dirty work in Web API.
I need to extract certain things from JSON, methods will do the job and return some result.
So where do I keep those methods?
do I need to write a separate library (dll)?
or just do this stuff in the controller?
I don’t think it can have a single answer – it depends on…
If you think this private method can be reused from some other controller in future, better to have a separate class, if you think it can be reused from separate modules (not just from controllers), a separate class library project can be the answer.
But if you consider this private method is designed to support for a specific action of a controller, you can write within controller, before taking any decision a few more parameters to be considered like unit testability or slimness of API etc.
You should keep your controller thin as much as possible. You can move logic code to service package, for example JSONService class or JSONLib.
I often use following layout:
controller/
lib/
service/
model/
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 7 years ago.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
What library i need for IEmailSender in asp.net mvc 5 ?
This is how code looks like:
public class PasswordResetHelper
{
private IEmailSender emailSender;
public PasswordResetHelper(IEmailSender emailSenderParam)
{
emailSender = emailSenderParam;
}
public void ResetPassword()
{
// ...call interface methods to configure e-mail details...
emailSender.SendEmail();
}
}
I take that code from a book for mvc 5 but it didn't work.
What i do wrong ?
P.S. Sorry for bad english.
You seem to be looking for a piece of code that will send emails for you. This isn't in that book.
The code you show is in a chapter that's titled "Building Loosely Coupled Components":
[...] one of [the] most important features of the MVC pattern is that it enables separation of concerns. [...] A simple example will help put things in context. If we were writing a component called MyEmailSender to send e-mail messages [...]
Emphasis mine.
They're trying to teach you the concept of building good, maintainable, testable software through separation of concerns and dependency injection.
If you're just looking for copy-pasteable code to implement an email sending class, you've bought the wrong book.
If all you're looking for is code to send an email, see How to send email in ASP.NET C#.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
How to get file from disk and write it to response?
We have some files on disk, and I want to allow logged users to download them.
I restricted access to them via direct link, so I just need how to get them from disk and give them to users via asp.net application.
Thanks
You can just use Response.TransmitFile method, like this:
protected void SomeButton_Click(object sender, EventArgs e)
{
string fileName = #"D:\somepath\somefile.doc";
Response.TransmitFile(fileName);
}
There is also another method Response.WriteFile. You can read difference between them here
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 8 years ago.
Improve this question
Its posible get all available twig blocks names inside a block? how?
You can do it. There are two main parts in the workflow of any programming language or scripting language workflow, lexing and compiling. In the compiling part, the Twig builds the token tree and then compiles it into a HTML (Twig internals).
All of that is called inside Twig_Environment class, which is used as a service inside Symfony. So what you could do is override the Twig_Environment tokenize method and get all the tokens you need there. You can then override the original service with your own modified extension.
This is how you would be able to return all the token names. You can adapt this to suit your needs. You can also override render and/or parse methods if you need the token tree itself, or you can write your own more complex additional functionality which you could call from the template itself. The possibilities are endless. Just mind to keep your code separate from the original Twig implementation (use overrides) so that you can update more easily.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Improve this question
We use breeze with API controller.
I want display what dates we have in database to the end user without converting them into UTC.
Same in case if uses chooses any date in the UI it should be saved as it was selected.
I know that JSON.NET date serialization sucks. Also on DOM elements are bound to model properties and it is quite big job to convert date fields into string.
Can you please advise for a fix solution?
I did try implementing custom DateTimeConverterBase and hook it through GLOBAL.ASCX however for some reason my overwritten method does not invoke!
Any help would be appreciated.
Simplest way to do this might be to replace Breeze's breeze.DataType.parseDateFromServer method.
See the answer to this post for more information: breezejs-date-is-not-set-to-the-right-time