Codeigniter - Is it possible to redefine anchor function - codeigniter

I have human friendly urls without index.php. I had to modify .htaccess file for that. Actually I always use Codeigniter like this. My url-s always look like this:
www.example.com/controller/function/parameter
So if I have an extra url parameter, then the url looks like this:
www.example.com/controller/function/parameter?archive=2013
Now what I want to do: If there is 'archive' parameter in the url, than also add that to the url when anchor function creates a link.
We have some different stuff every year (like stylesheets), so I need to make this navigation automatic. Am I thinking in the right direction?

And the answer is "Yes".
I slightly modified the solution from here:
How to extend anchor() function to anchor_admin() in CodeIgniter?

Related

Magento: Rewriting URLs dynamically depending on conditions?

I have this problem:
I have a default route that looks like this: .../myapp/index.php/config/configuration/test/product_id/51
As you see, this leads to the ConfigurationController and in there to the testAction function. Thats fine and it should stay this way. What I want to change though is the "config part" of the URL.
So instead of
http://somedomain.de/myapp/index.php/config/configuration/test/product_id/51
I want
http://somedomain.de/myapp/index.php/furniture/configuration/test/product_id/51
to lead to the same location (ConfigurationController and in there to the testAction function). The part that is changed, is not static, its the attribute set name of the product. So instead of furniture it can be computer or something else. I can already get this from the product, So all I need is the rewrite stuff.
Ideas how to do that? THANKS!
In the module's config.xml you can change the frontend/routers/your_router/args/frontName which will allow you to use a different name (like furniture). If its an adminhtml controller, you have to use an adminhtml router but the rest is the same.
You can use a router, just like Magento does for CMS pages (explained in the second part of this article : http://alanstorm.com/magento_dispatch_admin_cms_default_routers)

mvc 3 partials and usage

We meet again stackpeople!
I have been using the last 2 days trying to find the answer I need.I can't seem to find a straight forward answer on WHEN to use partialviews I know you can use em for like login component and all the other fancy stuff
.
But what about the navigation bar ? I tried making the navigationbar with partials and Ajax.htmlactionlink but then the problem comes, I know since its just a partial my URL won't get rewritten which means on f5 it will always update my home/index since no URL was given . Is this cus I can't make my navi like that or just because im plain stupid ?:)
Partials should be used to avoid code duplication. Create one if you find yourself writing the same view code over and over again.
A navigation bar sounds more like something that should be in the layout. You can use Sections in Razor and ContentPlaceHolder for the webforms view engine if you want to let pages customize the layout.
I don't think the partials have anything to do with it(it shouldn't, partials are just a way to split up source files so you can reuse them later).
I'm guessing the problem lies in the use of AjaxhtmlActionlinks, why would you want to do an Ajax call to redirect the user?
Try using the normal #Html.ActionLink()

Passing variable without using $_GET or URI segments - CodeIgniter

I have a blog where I want the user to click a link to be able to invert the colour scheme (from dark on light to light on dark). This link will be available on each page of the blog.
If I wasn't using CodeIgniter, I would create a link with a parameter (e.g. "index.php?inverted=true") and in my controller detect if $_GET['inverted'] was set, set a $_SESSION variable. The link would be changed and the additional CSS file would be added when $_SESSION is set. The link's new href would be something like "index.php?inverted=false" and the $_SESSION variable would be unset. It would work site-wide and regardless of the rest of the URI.
I've tried using the uri_segement functions in CodeIgniter, but because this needs to be across the whole site, my URIs change (sometimes just "index.php/controller/function", other times "index.php/controller/function/para1/para2/para3"). Therefore I can't just make my link: [href="$_SESSION['REQUEST_URI'] . "/inverted"] and then detect if that URI segment exists because I don't know which number the segment "inverted" would be. Also, if a user is on the same page and clicks the link twice, the URI keeps adding "/inverted" again and again.
I made a mock form so I could use the $_POST array instead, but I know this isn't good practice.
Any suggestions?
Make the link submit a form via POST as you described, then set the SESSION variable, after that, issue a redirect to the referring page (HTTP_REFERER). You can do something similar to toggle this option off.

Yii Url Rewrites

I got static pages to rewrite by modifying the urlManager like this.. 'login'=>'user/login'
which allows www.site.com/user/login.php to display as www.site.com/login.php
The goal is to be able to take user/ out of everything under the user directory.
Allright to fill in the blanks here...a solution
'<_a:(login|index|update|etc)>' => 'user/<_a>',

Ajax # and scroll-to #

Is it possible to have both an "AJAX" hash mark # as well as a scroll down to one?
Thanks.
No.
The # is a special character in a URL, it marks the rest of the URL as a fragment identifier, so everything after it refers to an HTML element id, or a named anchor in the current page. (Source)
What's the shebang/hashbang (#!) in Facebook and new Twitter URLs for? - it's only for Googlebot.
Yes.
If you really want to have both, the scroll-to bit can be fudged width JavaScript. It wouldn't be pretty.
As far as I know, # is not allowed in a fragment identifier. You could encode it as %23 and do something with that maybe.
If you're doing on-page stuff that you would like to be able to scroll to, you could just hijack links by adding a certain class to them or something.
Also, consider reading up on history.pushState and such on:
https://developer.mozilla.org/en/DOM/Manipulating_the_browser_history

Resources