I am using ajax via js helper in my cakephp application;
for this I am using following code.
echo $this->Js->link('test','/controller/test/', array('before'=>$this->Js->get('#loading')->effect('fadeIn'),'success'=>$this->Js->get('#loading')->effect('fadeOut'),'update'=>'#mydiv'));
It is working fine.
But when I am using this code on view page,which is rendered by ajax, it i not working.
when i check the page source i found that script for this view is not added in the buffered script.
I guess buffered script is created when the page is load.In my case when page is loaded specific content is not loaded so script for this layout is not added in the buffered script.
Please guide me is there any other method by which i can do this or i have to do it by custom jquery or another method.
You should use evalScripts option in your Ajax Link. Here is the code:
echo $this->Js->link('test','/controller/test/', array('before'=>$this->Js->get('#loading')->effect('fadeIn'),'success'=>$this->Js->get('#loading')->effect('fadeOut'),'update'=>'#mydiv', 'evalScripts' => true));
And at the bottom of your Ajax view file. Be sure to include:
<?php echo $this->Js->writeBuffer();?>
Related
I have a login system maded with AngularJS. Now I want that if somebody is not logged in the template is blank. If somebody logs in the template will continue. The problem is that when you load the page the templates loads also. So when you log in you get a blank page, you need the reload the page and then its working.
Is there a function that refresh the template? So that you don`t have to reload the page?
When you use Angular it's best to have the web server serve static content (images, css, js, and static html) and data (almost always JSON).
In your case I would always serve the template and use ng-show and/or ng-hide to toggle the template display. Here's a simple example:
Instead of
<?php
echo "Hello " + $name;
?>
Do this
greeting.html
<div ng-show="authenticated">{{name}}</div>
greeting.json web service (I'm not a php person, my php might not be entirely correct):
<?php
json_encode($name)
?>
My problem is that I want to render a pdf inside a CakePhP view.
So I have a view with some html/php and at the end of the page I want to render some pdfs (I don't want to link pdf, really need to render them on the same page).
If you have any idea on how to do it that would be great :)
Thank you.
You cannot mix HTML and PDF and expect the browser to display it correctly, that won't work. You'll either have to convert the PDF to HTML, or display the PDF in an iframe.
For the latter to work you usually need to send a Content-Disposition of type inline, and of course it requires a browser that either supports PDF natively, or has an appropriate plugin installed.
Here's some basic example code. In the view:
<p>Some html</p>
<iframe width='123' height='456' src='/path/view_pdf'></iframe>
And then in the linked controller action respond with inline PDF data, which is pretty easy in Cake 2.x:
public function view_pdf()
{
$this->response->file('/path/to/the/file.pdf');
$this->response->header('Content-Disposition', 'inline');
return $this->response;
}
For more information check the Cookbook.
What is the most conventional way to make an AngularJS single page app automatically reload in the browser every time I change its code?
In other words, if I have a code editor open editing the HTML for the AnguarJS single page app, and a browser at that app, side-by-side on the same screen, hitting Save in my editor should instantly trigger the browser to refresh.
Alternatively, same scenario as above except instead of hitting Save on my editor, I did a Commit in my VCS.
Use Grunjs watch task for this.
That is the work of your task runner like gulp or grunt to watch the changes over specified files and perform action. None of this is related to angularjs
I'm using the jquery linkify plugin on a relatively simple Backbone view. Links to web pages outside this app work properly and using browser view source, I see the mailto links are properly generated. But clicking a mailto link appends /mailto:q#example.com to the current URL (e.g., http://example-acme.staging.myservername.com/mailto:q#example.com).
If I copy the generated HTML using Inspector and paste it into the source of arbitrary pages (not in this app), the mailto links function as expected, opening a new message window from my mail client. Problem is the same in Chrome and Firefox.
Have you seen and fixed this issue?
Just for closure: I added an event handler in the handler use window.location.assign(mailto) and that gets the job done. Not necessarily 'correct' but practical. #Brad, thanks for chiming in!
I am implementing PDF file generation and I have completed it using this link:
http://bakery.cakephp.org/articles/kalileo/2010/06/08/creating-pdf-files-with-cakephp-and-tcpdf
After generating PDF, it calls another function that performs update of my database. And should redirect to index page. I have done my database update. Only problem in redirecting to index page. When I am redirecting to index page PDF logic is not implementing.
I think it is because of i have set layout for pdf so both index page and pdf creation not works one after another.
If you have set the PDF layout as stated on the Bakery, you can not redirect the user.
The PDF layout sent a header to your browser that states PDF content is coming it's way. A HTTP redirect is not PDF content, so this will not work.
If you want the PDF generation to be done on the background and not "on-the-fly" in the user's browser window, just drop the PDF layout and use your 'default' layout instead. You can then just call $this->redirect from your controller.