How can I solve routing in HMVC? - url-routing

I am working on a cms project which will be used to publish news sites. I am using i18n plugin for multilingual issues. the problem is at routing. I have module called news and method page in it and route is set as
$route['page/test'] = 'news/page/1';
this works without problem when i go to
http://localhost/site/page/test
problems begin when i start using i18n localization plugin. then it only works with this url:
http://localhost/site/en/news/page/test
I want the url to be wiout the news segment. What can I do to solve this?
Thanks in advance.

This will work on any controller, with or without a language string
$route['^([a-z]{2})/(.*)'] = '$2';
$route['^([a-z]{2})'] = $route['default_controller'];

Looks normal to that it don't work anymore with the route cause it is missing the "/en/"
Did you try to put :
$route['en/page/test'] = 'news/page/1';
or
$route['en/page/test'] = 'en/news/page/1';
(I don't know the i18n plug)
If it works the solution might be in using a wildcard:
$route['(:any)/page/test'] = "news/page/1";
or
$route['(:any)/page/test'] = "$1/news/page/1";
(again i don't know the plug i18n plug works)

Related

Adding a hash prefix at the config phase if it's missing

I am now integrating phantom in my Angularjs-based web application.
This fine article says that I should call the $locationProvider.hashPrefix() method to set the prefix to '!' from SEO reasons(allow crawlers to intercept the _escaped_fragment component of the URL).
The problem is that I haven't though of the earlier, and some of my URLs look as following:
#/home.
I though perhaps there is a way that I can implant this '!' char into the begging of the URL programmatically(in case it is not already there) at the config function of the APP, instead having to edit a lot of markup manually.
I've had similar problem and manually (search/replace) went through all the links and fixed them.
The other problem I had was the external sites were using the old format i.e.
http://plinkplink.net/#/event/3
instead of the new format
http://plinkplink.net/#!/event/3
The fix I did for that is not strictly speaking angularjs idiomatic but it does the job. I've added this script to the header of my page. It simply redirects pages with # to pages with #!:
<script>
var loc = window.location.href
if (loc.indexOf("#") != -1 && loc.indexOf("#!") == -1 ){
window.location.href = loc.replace("#", "#!");
}
</script>
I hope it helps.
Are you linking to the # value? ie - <a href="#/my/page"> If so, you shouldn't be. You should be linking to the url without the # prefix and I believe it'll solve your issue.

Sanitize string to using angularjs

I basically want to use tel tag to make a phone call.
<a class="callButton" href="tel: {{phoneno}}"></a>
I am using $compileProvider to remove unsafe tag which comes by default, It works perfectly fine post 1.0.4v of angularjs. However below this version it doesnt work. Can anyone suggest how to implement this feature using angular version 1.0.4 or below?
Here is the sanitizing code which I am using in js file
app.config(['$compileProvider', function ($compileProvider) {
$compileProvider.urlSanitizationWhitelist(/^\s*(https?|ftp|mailto|file|tel):/);
}
Assume I have already defined app variable.
P.S. This is an enhancement for particular app which basically works below 1.0.4v
Thanks
Add this to your scripts after angular is loaded.
I asume your on 1.1.5, but change to whatever you need the version to be.
http://code.angularjs.org/1.1.5/angular-sanitize.min.js
Example:
sanitizeSomething = function(string) {
return $sanitize(string);
};
sanitizedString = sanitizeSomething(string);

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.

AngularJS $routeProvider, fallback to default link navigation

So not 100% of my site is "powered by AngularJS" some of it is just simple static HTML like a landing page or content oriented stuff, which is simple HTML for obvious reasons.
The only way I can seem to get a link to navigate normally is like this:
$routeProvider
.when('/plans', {templateUrl: '<%= asset_path('ng/views/start.html') %>'})
# Catch all
.otherwise({ redirectTo: (p,loc) -> window.location = loc })
It feels like the catch all should be simpler like I could do .otherwise(false) and it would just navigate normally. Same goes for `.when('/something'/, false) but I don't see anything in the docs that suggests this is possible.
Does anyone know of a better way to do this?
Edit 1:
One solution I've found is to use target='_self' in the link.
The other is apparently to set the "base url" of the application as outlined in the docs. Then any links outside of that base should navigate normally. However that doesn't seem to work as outlined and the example doesn't match what the documentation is suggesting either.
just creating a link to it external file
if you are using hashbang urls (e.g. #/plans) then you should be all set, if you are using html5 history api ($locationProvider.html5(true)) then you need to namespace your app (set base[href] properly) and put the content outside of that namespace.
relevant code:
https://github.com/angular/angular.js/blob/4df45b20d460239a0f5001fb0dd59f95e2d0e80d/src/ng/location.js#L560
Another solution is to use target="_self" on that a element. Again this should be an issue only when html5 (history pushState) is being used.

Simple examples on how to use CakePHP pages_controller.php to create static pages

I am complete beginner to CakePHP but I am a bit knowledgeable in ROR.
Can somebody pls give me some simple examples on how to make use of pages_controller.php? I want to create static pages such as Home, About, and etc but I don't know how and where to start. I tried something like creating a about.ctp in the views and creating about_controller.php (this is how being done in Ruby on Rails) but I just got some errors.
I concluded that all of the static pages will only use 1 controller which is pages_controller.php but I dont know how.
I tried reading the article found on this link:
http://book.cakephp.org/view/958/The-Pages-Controller
but it doesn't give me anything that will help me learn how to use it.
This is what I got from the page:
CakePHP core ships with a default controller called the Pages Controller (cake/libs/controller/pages_controller.php). The home page you see after installation is generated using this controller. It is generally used to serve static pages. Eg. If you make a view file app/views/pages/about_us.ctp you can access it using url http://example.com/pages/about_us
When you "bake" an app using CakePHP's console utility the pages controller is copied to your app/controllers/ folder and you can modify it to your needs if required. Or you could just copy the pages_controller.php from core to your app.
Can somebody pls show me or explain to me how??? I am a total beginner pls help.
It's pretty self explanatory.
Create a file in your APP/views/pages/ folder - e.g about_us.ctp
Type in your content. No layout; just the text, tables/images/etc
<h3>About my site</h3>
<p>bla bla la</p>
<?php echo $this->Html->image('my_img.jpg'); ?>
Save.
Go to www.site.com/pages/about_us - your page is served.
Pages is the controller to serve static pages. you don't need an about_controller, unless you need something more than just a static page.
You can change how the link looks by using routing.
You can set variables for use in your template as well:
about_us.ctp
<?php
$this->set('title_for_layout', 'My about page');
$this->set('active_link', 'about');
?>
<h1>My page!</h1>
etc

Resources