CakePHP: requestAction and problems with styles / scripts - cakephp

I have one problem with CakePHP and $requestAction. In the 1.3 manual of cakephp there is written
It is important to note that making a requestAction using 'return' from a controller method can cause script and css tags to not work correctly.
Now I got this case. The contents of $html->css() and $html->script() are not displayed in the final view after using a $this->requestAction() in combination with return in the controller.
Does anybody know a workaround for this problem? How to use styles and scripts together with $this->requestAction(<...>, array('return'))?

Related

The purpose of dot-extension files with json-data

In process of my self-study AngularJS and UI Grid, a few times I have seen dot-extension files (i.e. foobar.dot) with json data. What is the purpose of it?
{
"Foo":"Abc",
"Bar":"Xyz"
}
For exmaple, the data from this page is rendered using the following dot-file
The use of the dot rule is to make sure the inheritance is in use. With out it scope models might not work as they should in your controller.
For more detailed explanation: https://github.com/angular/angular.js/wiki/Understanding-Scopes

tinyMCE aborts with "Object doesn't support this action".

I'm trying to use the AngularJS directive ui-tinymce with tinyMce 4.0.25 and IE10, and am unable to get it to work at all.
My html looks like this:
<textarea ui-tinymce ng-model="fubar"></textarea>
In my controller, I have:
$scope.fubar = "this is a <b>test</b>";
It all goes badly at these two lines in the tinymce initialization code itself.
Theme = ThemeManager.get(settings.theme);
self.theme = new Theme(self, ThemeManager.urls[settings.theme]);
The first line sets Theme to undefined and the last line aborts with the message "Object doesn't support this action". The value of ThemeManager.urls[settings.theme] is "http://localhost:57683/Scripts/tinymce/themes/modern", which seems right.
I can no longer find it, but I'd previously found a post where this issue was due to this code being executed before some other part of tinyMCE had been loaded. The solution there was to use a certain tinyMCE option that forced loading in a certain way, however that option has been removed in tinyMCE 4.x. Even more frustrating is that I had tinyMCE working for days with my own directive when suddenly this occurred. I've simplified this to just using ui-tinymce (with the same result) to rule out any of my code as the culprit.
Mea culpa! I'd switched to using tinymce.js instead of tinymce.min.js and didn't realize that the min code expects the theme to be modern/theme.min.js (which I had) but the unminified code expects the theme to be modern/theme.js.

Do we need multiple controllers to implement routes in angularjs?

There is chance that I might not be able to explain my problem properly. Let me try.
I am developing a single page application using angular. This app basically displays the episodes of an online novel series. There is a navigation bar, which has query menus (Like, latest episode, episode of a particular date, episodes with a particular tag, etc). For each of these queries, i want a separate url.
/latest - should display the latest episode
/tag/:tagname - should return all episodes with that tag.
For all these queries, the resultant view is the same (list of episodes). So I will be using the same partial for all routes.
My question is, Should I actually create a new controller for each query? like, LatestEpisodeController, TagController?
Is there anyway I can use the url to determine what the user wants and run that query from within the same controller?
Ofcourse you can use same controller in routing definition, the question is what is the purpose of that? It will be worse to debug it later, if you have a shared functionality it's better to turn it into a factory or service and then use in controllers.
But the answer is YES, you can use same controllers and implement different behaviour basing on i.e. $location.path()
yes you can use single controller for multiple routing..
you can create different functions in controller and in each function do the according job.
In my case I have created different html page for different url and registered same controller for the html pages and in the html page I have called controller method using ng-init in div portion.
You can use same controller and same views as you wish...
$location can help you to get current path or full url if you want and you can call your service depends on your path...
here I write a little example for you to get the idea
PLUNKER

prevent Mustache from loading template from cache

I'm using Backbone.js with mustache.js, and I'm loading my templates using ajax. my problem is that the templates are being loaded from cache(refreshing using ctrl+F5 if that matters!). Now I have made changes to the template but it's still loading the old version of it. It's working perfectly fine in incognito. Is there a way to prevent this? Maybe prevent Mustache from caching the template?
The code that renders the template is:
$.get(this.templatesPath + this.template, function(resTemplate){
var html = Mustache.render(resTemplate, that.personData);
that.$el.html(html);
});
My first thought was to use some other function instead of "Mustache.render()" like maybe "Mustache.to_html()". But looking at the
Source Code
reveals that to_html() merely calls render().
Any thoughts?
Apologies for digging up this very old question, but I was searching for the answer to a similar question and didn't end up finding it anywhere. This question is one of the first that shows up when searching "mustache disable caching".
I am using Mustache and Express with the mustache-express module. I was able to disable caching with the following:
const Mustache = require('mustache-express')();
delete Mustache.cache;
I hope this helps someone else in the future.

render a blank view in cakephp

i need to prevent a view to be rendered in a specified case but i can't understand how to prevent it to render.
I tried
$this->autoRender=false
but nothing happened, probably because i'm using an API engine that manage rendering differently from regular controllers. Anyone know any trick to do this?
Using $this->layout = 'ajax' does not seem to be enough.
But using these both lines works:
$this->layout = 'ajax';
$this->render(false);
While searching for a solution, I found this answer. Now when using CakePHP 2.4.x, you could use the following code in your controller:
$this->layout = false;
This will lead to just the view being rendered, without a layout.
It's an old question. The current cake-version is 3.x and there is a easy way to use a blank layout.
Only add the in the controller:
$this->viewBuilder()->autoLayout(false);
Try to use ajax layout $this->layout = 'ajax' this is the default empty layout, which is used for ajax methods.
public function function_without_layout(){
$this->viewBuilder()->autoLayout(false);
echo "hello Brij";
exit;
}
$this->layout = false; is deprecated in CakePHP version 3.
Use $this->viewBuilder()->autoLayout(false); for CakePHP version 3.
Add this in your controller:
$this->autoRender = false;
This works in my project.
The CakePHP 3 autoLayout(false) method from the other answer will still have the system try to locate a corresponding view/template file for the action you're calling. Since I needed no output at all, this didn't work for me, so I needed to also render an empty template.
Creating a blank .ctp file for every empty action you might need isn't an option really, because you'd normally want to have one and reuse it. CakePHP 2 had a $this->viewPath property which would let you configure the controller to look into the app/View folder, but it's CakePHP 3 alternative still looks into the corresponding controller and prefix folders. There is a not-so-obvious way to force CakePHP3 to look for a template in a root view path.
Create src/Template/my_blank_view.ctp
Add the following to your controller action:
$this->viewBuilder()->layout(false);
$this->viewBuilder()->templatePath('.'); // this
$this->viewBuilder()->template('my_blank_view');
Also, I'm using $this->viewBuilder()->layout(false) instead of autoLayout(false) because the latter kind of implies that there might be another layout set later, where the layout(false) just explicitly sets that there's no layout needed.
without knowing anything about API engine you're using, maybe try to make empty layout with empty content and call it in controller as $this->layout = 'empty_layout'

Resources