Using Yii 1.1.12. I have a CListView with ajax turned off:
<?php $this->widget('zii.widgets.CListView', array(
'dataProvider'=>$dataProvider,
'itemView'=>'_view',
'ajaxUpdate' => false,
)); ?>
The url for the link to the second page looks like:
http://www.example.com/products?Product_page=2
I want the url to look like:
http://www.example.com/products?page=2
How can I achieve this?
(A bonus would be to also describe how to get a url like http://www.example.com/products/page/2)
Update
As pointed out by elbek, I see the CListView has a pager property of type CLinkPager. This in turn has a pages property of type CPagination which has a property pageVar which is described as:
name of the GET variable storing the current page index. Defaults to
'page'.
Sounds like it could be what I'm looking for, not sure how to modify this from the CListView though.
Additionally to change the pageVar you have to modify the $dataProvider. You can do this when you are defining it in the controller action:
$dataProvider=new CActiveDataProvider('Products',array(
'pagination'=>array(
'pageVar'=>'page'
)
));
Alternatively you can of course modify the $dataProvider in the view itself before using it in the CListView : (not recommended-owing to separation of concerns)
$dataProvider->pagination=array('pageVar'=>'page');
$this->widget('zii.widgets.CListView', array(/*rest of your code*/));
But with this change, to make your url look like http://www.example.com/products/page/2 you'll need to slightly change the rule in urlManager from Suvera's answer:
'products/page/<page:\d+>'=>'products/index',
Note: If you don't need that type of url, you don't need the above rule, just specifying the pageVar does it.
enable the urlManager component on your config. And add the following rule at the top.
'urlManager'=>array(
......
'rules'=>array(
'products/page/<Product_page:\d+>'=>'products/index', //Add it in top
...........
...........
),
),
the above rule will create a url something like http://www.example.com/products/page/2
The value part in the rule products/index is products controller and index action (this is important, so point it out to your actual route).
you can even create urls whatever way you want.
ex 1:
'products/<Product_page:\d+>'=>'products/index'
will give you http://www.example.com/products/2
ex 2
'TheAvengers/vs/Loki/<Product_page:\d+>'=>'products/index'
will give you http://www.example.com/TheAvengers/vs/Loki/2
I think CListView has pager attribute(from its parent class)
You can try to set some attributes for this. I think it is CLinkPager instance.
Related
I want to create a routing in Kohana Framework Version 3.3.1.
I want URL like http://www.test.com/male/London and internally they will act like below URL-
http://www.test.com/list/search/London
I want to hide the controller and action name from the URL.
Any help is greatly appreciated.
This can be accomplished by using routes in bootstrap.php and/or a module's init.php file.
For example, you could set up a route for (male/<location>) and then your default controller would be list and the action search.
You could then access the location within the controller/action by using $this->request->param('location'); to be used in whatever DB query you need it.
Confused? Have a read through this section of Kohana Docs and it should all make sense.
You have to do two changes in your file:
Bootstarp file :
Route::set('list', 'male/<id>' )
->defaults(array(
'controller' => 'list',
'action' => 'search',
));`
And second is you can make your link like
href="<?php echo URL::site('male/'.id, TRUE) ?>">
And this route file should above at your default route file.
This is my first time round using Umbraco and I have created Document Types / Pages using the wrong naming format and now this has transpired into my page URL's, for instance /about-page/. How would I go about changing them to /about as I have searched the back-end admin panel and there dose't seem to be an option to change their link to document values.
Would anyone be able to provide a simple code based example using umbracoUrlAlias or umbracoUrlName how I could change this preferably in Razor.
Thanks
Editing #run yards Solution by digbyswift help in comment
Correct Solution:
Create Property on in Document Types which applies to all pages you want to change the URL
Call the name anything you want e.g Page URL and Possibly give it a new tab.
Call the alias umbracoUrlName
Type as text sting
Should not be Mandatory (As when you start replacing .Url with .umbracoUrlAlias within the views it will need to be present)
Tab as Generic
Click Save on top right on the page
Added screenshot for starter kit on Umbraco v7.2.5
Unless I'm very much misunderstanding your issue, you should just be able to change the name of your page and republish. This doesn't need an additional field, just change the value in the "Properties" tab and republish the page. This will automatically change the URL of the page.
You can also create a property called umbracoUrlName using a TextString property editor. If this has a value then it will generate the URL fragment for the page using this value, rather than the page name. This changes the URL for the page, rather than creating an alias, like umbracoUrlAlias.
Solution:
Create property on in Document Types which applies to all pages you want to change the URL
Call the name anything you want e.g Page URL and Possibly give it a new tab.
Call the alias umbracoUrlAlias
Type as text sting
Make it required (As when you start replacing .Url with .umbracoUrlAlias within the views it will need to be present)
Go into all your pages and rename them using the property you just created
Now with your code, say with the navigation where you have used .Url change it to .umbracoUrlAlias and the new URL's will be used.
Note if you don't use .umbracoUrlAlias the links will still be active i.e. they work but they won't be displayed in the address bar as .Url spits out the original ones associated with the page.
You can apply on URL names in web.config:
In section find:
<add key="umbracoUseDirectoryUrls" value="false" />
this will set url names for new created items to name.aspx
If you set this to 'true' then new items will be named like /name/
Additionaly you might want to avoid of Handling some urls by Umbraco pipline, just use this setting - add URLs which must be bypassed:
<add key="umbracoReservedUrls" value="~/config/splashes/booting.aspx,~/install/default.aspx,~/config/splashes/noNodes.aspx,~/VSEnterpriseHelper.axd" />
This view suppose to show a list of hyperlinks, each pointing to an external URL. The goal is for the user to click one of these links and have their browser open a new tab with the selected URL.
Currently I have the following markup:
#Html.ActionLink("SomeSite", "http://subdomain.mydomain.com/SomeSite")
This markup produces:
http://localhost:58980/AccessInstance/http%3a/subdomain.mydomain.com/SomeSite
instead of :
http://subdomain.mydomain.com/SomeSite
What can I change in my markup to make this work as I expect?
You don't need to use #Html.ActionLink for that. Just use a plain A tag:
SomeSite
Html.ActionLink is specifically for generating links to actions defined in MVC controllers, in the same app. Since you're linking to an absolute URL, you don't need any of the functionality that Html.ActionLink provides.
Two ways :
1. update the database column with full link:
eg SQL:
update ProductTable set ProductLink='http://www.example.com/Product/Mobiles' where ID=123
In asp mvc view
View
2. Hardcode the http part and list from model
View
Hope helps someone.
While a ViewBag is overused and not the best choice most of the time this is something that I had done when inheriting someone else's mvc app to do a quick fix for a URL that I needed to redirect to with a specific dynamically changing querystring parameter
<a target="_parent" href="http://localhost:56332/services/#ViewBag.factory">View Service</a>
Using .NET Core 6
This seems to be the most correct answer:
Link
This will generate the following result:
As you can see at the bottom left corner of the window before clicking the link, the URL address was rendered as it is (NOTE: The cursor was recorded out of place for some reason, that's a ShareX problem, ignore it).
Than link will be directly saved as a nvarchar(750) type (probably any character like type will do the work). No changes to the original link were made before saving it or on reading:
You need to take into account your RouteConfiguration.
routes.MapRoute(
name: "Default",
url: "{controller}/{action}"
because you are specifying the action link as the entire link that you want to redirect.
I would recommend that you use the #rossipedia answer because you can make tricky things like putting a span inside the link
Here to display link that are clickable in index page
<td>
#Html.ActionLink(item.FileName, "../Uploads/Catalogue/"+item.FileName)
</td>
I'd like to set the 'active' class on an Ember link-to helper for more than one route, where the routes are not nested.
ie. if I have a link to route1 I would like it to be active when the current route is route1 or route2.
Something, like:
{{#link-to 'route1' currentWhen="route1, route2"}}Things-N-Stuff{{/link-to}}
My next ideal scenario is set (or find) a boolean when the route is active and then do something like:
{{#link-to 'route1' class="isRoute1:active isRoute2:active"}}Not-as-good{{/link-to}}
But I'd rather pick it up for free. Perhaps there is a default isRoutename boolean that isn't in the docs yet...?
No answers yet. I ended up doing this:
{{#linkTo "things" tagName="li" href=false}}
<a {{bindAttr href="view.href"}} {{bindAttr class="isThingsLinkActive:active"}}>Things</a>
{{/linkTo}}
And then in the App.ApplicaitonController
isThingsLinkActive: function(){
return ['things.index','thing.index','stuff.index'].contains( this.get('currentPath') );
}.property('currentPath'),
It means I need to have something like thins in my app controller for each 'overloaded' link. Wouldn't it be cleaner to capture this entirely in the template using default flags/attributes generated by ember? I'm open to a more elegant solution... anyone?
According to the link-to#active documentation, you can do this by using a space delimited "currentWhen", but this requires Ember 1.8.
{{#link-to 'route1' currentWhen="route1 route2"}}Things-N-Stuff{{/link-to}}
This may also be a feature you can enable on earlier builds:
See 'ember-routing-multi-current-when' on https://github.com/emberjs/ember.js/blob/master/FEATURES.md
Alternatively, you can override the link-to helper with one of the methods described in this SO post:
Is there a way to pass an array to currentWhen in EmberJS?
Currently as of 3.2 the correct syntax is:
{{#link-to 'fruits.index' current-when="fruits.index apples.index"}}Link text{{/link-to}}
Sorry, tried to edit the original answer but the change is less than 6 characters.
I have actions that take string id parameters that are based on a username which can include characters that require encoding, for instance "user?1"
If I use ActionLink() to generate the links, passing the string without encoding, it generates a link like this: http:\\localhost\controller\action\user?1, and the action gets passed "user" as the id.
If I UrlEncode() the string before passing it to ActionLink, then the link generated is: http:\\localhost\controller\action\user%253f1 as ActionLink will then encode the '%' character for you. Besides this looking ugly, it then also generates a HTTP Error 400 - Bad Request when following the link which I've not yet tracked down the cause of.
Is there any way that I can generate the url like: http:\\localhost\controller\action\user%3f1?
How about removing the ? character or replacing it with something else like a dash (-) or underscore (_) ?
You should look in the Global.asax.cs file
add another route for your convenience, in this case, the ff. might work:
routes.MapRoute(
null,
"{controller}/{action}/user/{id}",
new { controller = "Home", action = "Index" }
);
I guess this is what you want, to separate action for each users, but i suggest you use cookie for this purpose.
PS: Remember to put that one on top of your default route since routing is trying to match from top to bottom.
you can create a jquery plugin that check all the links and replace the char that you need to replace with the new value.
and after apply this plugin to all the ActionLinks