nuxtjs route map in order - vue.js

I have an issues with nuxtjs route naming.
Ex: my pages folder is
page:
-|blog:
-|_categorySlug.vue
-|_postSlug.html.vue
-|service:
-|index.vue
When i access url like
example.com/blog/demo-post-slug.html -> route map to /blog/_categorySlug.vue
example.com/blog/demo-category-slug -> route map to /blog/_categorySlug.vue
Because _categorySlug.vue place in the first order inside dir blog.
When i change the file name _postSlug.html.vue to _aPostSlug.html.vue to make it become the first order.
page:
-|blog:
-|_aPostSlug.html.vue
-|_categorySlug.vue
-|service:
-|index.vue
It's all right but the file naming isn't good. Anyone can give me an suggestion for this?
Thanks!

Related

Play framework: Dynamic routing depending on version number

I'm trying to dynamically define a version in the URI routing.
My immidiate ideas were to
a)
I've configured in the application.conf a row stating my current version:
myApp.ver = 0.1
I wan't to use it in the routes file as part of the URI, for example:
GET /myApp/{version}/welcome controller.myApp.Welcome()
The idea is not to pass the version number to the Welcome() method
but to get the version from the application.conf file.
I've searched for defining parameters in the route file but didn't find information that helped me.
b) Another idea was to have a variable in the routes, something like:
CurrentVersion = 0.1
in the routes file and use it in the URI.
How can I solve this? I havn't found an example for this.
Thanks.
If you want to do this for every route, it should be possible to set the application.baseUrl to include your version number. To do this conveniently you can define the version in your application.conf instead of the Build.scala file, as described here.
myApp.name = myApp
myApp.ver = 0.1
application.baseUrl = ${myApp.name}/${myApp.ver}
If you want to do it only for some routes, there doesn't seem to be a simple solution. If you could ignore parameters in routes, I'd say use a regexp parameter and verify it in your global router - unfortunately this doesn't seem possible without passing the parameter to the controller.
So I see two other options:
Hardcode the version number in the routes file and do a search and replace every time it changes.
Create a plugin for the sbt build process and let it replace the version in your routes file.
In Play 1.2.x, in your conf/routes file, add a route like this:
GET /myApp/${play.configuration.getProperty("myApp.ver")}/welcome myApp.Welcome()

Rails 3 Routes - prepend all url paths with set string

I've been asked to change the routes on a Rails project such that the routes will only respond to requests where the app name (or other arbitrary string) is the first string after the domain name, e.g.
www.thething.com/appname/users/sign_in instead of www.thething.com/users/sign_in
www.thething.com/appname instead of www.thething.com
www.thething.com/appname/search instead of www.thething.com/search
I've suggested using a subdomain appname.thething.com instead, but the client is quite specific about wanting the URL in the above format.
www.thething.com will be a splash page which will contain a link to www.thething.com/appname, with the intention of adding additional apps/pages in future with new folder names.
Is there an easy way of modifying the routes file so that all routes will get the .../appname prepended to all resources and routes, while being after the domain?
One option is wrap all existing routes in: namespace :appname do ... end, like so:
# config/routes.rb
Appname::Application.routes.draw do
namespace :appname do
# existing routes go here
end
end
I'm not sure if this is the most elegant solution, but it will prepend /appname to all the routes.

Completely custom path with YII?

I have various products with their own set paths. Eg:
electronics/mp3-players/sony-hg122
fitness/devices/gymboss
If want to be able to access URLs in this format. For example:
http://www.mysite.com/fitness/devices/gymboss
http://www.mysite.com/electronics/mp3-players/sony-hg122
My strategy was to override the "init" function of the SiteController in order to catch the paths and then direct it to my own implementation of a render function. However, this doesn't allow me to catch the path.
Am I going about it the wrong way? What would be the correct strategy to do this?
** EDIT **
I figure I have to make use of the URL manager. But how do I dynamically add path formats if they are all custom in a database?
Eskimo's setup is a good solid approach for most Yii systems. However, for yours, I would suggest creating a custom UrlRule to query your database:
http://www.yiiframework.com/doc/guide/1.1/en/topics.url#using-custom-url-rule-classes
Note: the URL rules are parsed on every single Yii request, so be careful in there. If you aren't efficient, you can rapidly slow down your site. By default rules are cached (if you have a cache setup), but I don't know if that applies to dynamic DB rules (I would think not).
In your URL manager (protected/config/main.php), Set urlFormat to path (and toptionally set showScriptName to false (this hides the index.php part of the URL))
'urlManager' => array(
'urlFormat' => 'path',
'showScriptName'=>false,
Next, in your rules, you could setup something like:
catalogue/<category_url:.+>/<product_url:.+> => product/view,
So what this does is route and request with a structure like catalogue/electronics/ipods to the ProductController actionView. You can then access the category_url and product_url portions of the URL like so:
$_GET['category_url'];
$_GET['product_url'];
How this rule works is, any URL which starts with the word catalogue (directly after your domain name) which is followed by another word (category_url), and another word (product_url), will be directed to that controller/action.
You will notice that in my example I am preceding the category and product with the word catalogue. Obviously you could replace this with whatever you prefer or leave it out all together. The reason I have put it in is, consider the following URL:
http://mywebsite.com/site/about
If you left out the 'catalogue' portion of the URL and defined your rule only as:
<category_url:.+>/<product_url:.+> => product/view,
the URL Manager would see the site portion of the URL as the category_url value, and the about portion as the product_url. To prevent this you can either have the catalogue protion of the URL, or define rules for the non catalogue pages (ie; define a rule for site/about)
Rules are interpreted top to bottom, and only the first rule is matched. Obviously you can add as many rules as you need for as many different URL structures as you need.
I hope this gets you on the right path, feel free to comment with any questions or clarifications you need

Yii: CMenu items for different module

I'd like to make a menu in Layout which the items are linked to other different module.
e.g:
Item "Product" linked to an action in Product Module, item "Service" linked to an action in Service Module.
It won't work when I set the 'url'=>('product/<controllerID>/<actionID>') and 'url'=>('service/<controllerID>/<actionID>') because once we're in Product module and click the menu "Service", the URL become
index.php?r=product/service/<controllerID>/<actionID>
instead of
index.php?r=service/<controllerID>/<actionID>
and it will be 404 error. (for sure, because the Service Module isn't inside Product Module but the URL makes it looks like that).
Any solution for this?
Check the createUrl() documentation :
the URL route. This should be in the format of 'ControllerID/ActionID'. If the ControllerID is not present, the current controller ID will be prefixed to the route. If the route is empty, it is assumed to be the current action. If the controller belongs to a module, the module ID will be prefixed to the route. (If you do not want the module ID prefix, the route should start with a slash '/'.)
That last line tells us everything. Best thing to do for you is start all the routes with a / :
'url'=>array('/<moduleID>/<controllerID>/<actionID>')
Check this
'url'=>$this->createUrl('/<moduleId>/<controllerID>/<actionID>')

Trying to place avatar on every page in PHPbb Forum. Only showing up in index page... any ideas?

The website that im trying to make it work on is http://www.phone7forum.com/
The way I get it to show up on the index page is adding this code to the core index.php page right below this:
// Assign index specific vars
'S_AVATAR' => get_user_avatar(
$user->data['user_avatar'],
$user->data['user_avatar_type'],
$user->data['user_avatar_width'],
$user->data['user_avatar_height']
),
Then I can use {S_AVATAR} in my template but it ONLY shows up in the index file... So another phpbb guy suggested that I take that same code from above and place it in the includes/functions.php file right below this:
// The following assigns all _common_ variables that may be used at any point in a template.
I did that, and though it seemed to "try" and work I clicked on a few pages outside the index page and got a fatal error message:
Fatal error: Call to undefined function get_user_avatar() in /home/content/04/6534704/html/phone7forum/includes/functions.php on line 4385
Does anyone have any ideas?
IIRC get_user_avatar() is a function from functions_display. If you want to use it in the functions file, you have to include it.
Put it into an if condition to have it only load if you're on a page where function_display isn't already included:
if(!function_exists('get_user_avatar')){ include_once($phpbb_root_path . 'includes/functions_display.' . $phpEx); }