At the moment i have a glossar controller with an actionAnzeige()-method.
For this action i need GET-paramter named item.
Now i could use this url: www.xy.de/glossar/anzeigen?item=programming
But i want to use this: www.xy.de/glossar/programming
I've added this route to the rules:
'glossar/<item:\d+>'=>'glossar/anzeigen',
and now i can generate the url i want to use:
<?php echo Yii::app()->createUrl('glossar/anzeigen', array('item' => $glossarItem->Url)); ?>
But if i visit the created url, i get a 404 error.
You can use this, which accepts characters or numbers:
'glossar/<item:.+>'=>'glossar/anzeigen',
You have to use w+ instead of d+ since item takes letters instead of digits
'glossar/<item:\w+>'=>'glossar/anzeigen',
Related
I know how to to specify routes for page components using Mason::Plugin::RouterSimple, for example given a url of:
/archives/2015/07
I can create a component archives.mc as this:
<%class>
route "{year:[0-9]{4}}/{month:[0-9]{2}}";
</%class>
Archives for the month of <% $.month %>/<% $.year %>
and similarly I can create a news.mc component that will handle urls of:
/news/2012/04
and that's fine (and very elegant!) but now what I want is to be able to handle urls like the following ones:
/john/archives/2014/12
/john/news/2014/03
/peter/news/2015/09
/bill/archives/2012/06
etc. I know I can write the route rules as:
<%class>
route "{user:[a-z]+}/archives/{year:[0-9]{4}}/{month:[0-9]{2}}", { action=> 'archives' };
route "{user:[a-z]+}/news/{year:[0-9]{4}}/{month:[0-9]{2}}", { action=> 'news' };
</%class>
but then the requests have to be handled by two different components. How can I route a request to different components? archives.mc and news.mc won't be matched by Mason because there's a username before the name of the component.
The problem is that, while urs like /archives/2014/12 can be easily handled by an /archives.mc component, for urls like /john/archives/2014/12 and /bill/archives/2012/06 it's not clear where to put the archives component.
Mason will try to match the following components (it's a simplified list, please see Mason::Manual::RequestDispatch):
...
/john/archives.{mp,mc}
/john/dhandler.{mp,mc}
/john.{mp,mc}
but finally...
/dhandler.{mp,mc}
So my idea is to put a dhandler.mc component in the root directory:
<%class>
route "{user:[a-z]+}/archives/{year:[0-9]{4}}/{month:[0-9]{2}}", { action=> 'archives' };
route "{user:[a-z]+}/news/{year:[0-9]{4}}/{month:[0-9]{2}}", { action=> 'news' };
</%class>
<%init>
$m->comp($.action.'.mi', user=>$.user, year=>$.year, month=>$.month);
</%init>
If the url matches the first route, it will call the archives.mi component:
<%class>
has 'user';
has 'year';
has 'month';
</%class>
<% $.user %>'s archives for the month of <% $.month %>/<% $.year %>
(I used a .mi component so it will be accessible only internally).
The dhandler can be improved (better regexp, can check users from a database table and deny the request, etc.)
Since my archives and news components can accept POST/GET data, and since I want to accept any data, I can just pass everything with:
$m->comp($._action.'.mi', %{$.args});
Not too elegand, but it looks like it does its work.
Hi i am want an html code that replace XXXXXXXXXXXXXXXXXXX value from my url with my user given value and generate a new url
Below is My URL
https://www.facebook.com/connect/uiserver.php?method=stream.publish&redirect_uri=https://www.facebook.com&api_key=192236710846214 &picture= XXXXXXXXXXXXXXXXXXX%3Flvh%3D1& source=https://dl.dropboxusercontent.com/u/61636013/achille.swf&set=a.106020872877897.12204.100004099541771&type=1&theater &name=Posted by Karthik%C2%AD&caption=Kaur & comment%C2%AD&description=%C2% For Fun
Best is that you use php:
<?php
$x="XXXXXXXXXXXXXXXXXXX";
$location= "https://www.facebook.com/connect/uiserver.php?
method=stream.publish&redirect_uri=https://www.
facebook.com&api_key=192236710846214 &picture=".
$x.
"%3Flvh%3D1& source=https://dl.dropboxusercontent.com
/u/61636013/achille.swf&set=a.106020872877897.12204.
100004099541771&type=1&theater &name=Posted by
Karthik%C2%AD&caption=Kaur & comment%C2%AD&description=%C2%";
header("Lcation:".$location);
?>
Any idea about how can I send parameters in url query and get values of these parameters in next page
In first template I wrote this code
<a href ='r_rss/openOneNews?url={rss_link}'>{rss_title}</a>
Q:How can I get url parameter value in ExpressionEngine and use something like this in following page:
<iframe src = 'url' />
Thanks
See this answer - you want to use Mo' Variables to get the query string, which will then convert to a variable tag:
<iframe src = '{get:url}' />
Ahmed - please don't cross-post your question:
https://expressionengine.stackexchange.com/questions/14546/form-post-values
https://expressionengine.stackexchange.com/questions/14548/sending-paramters-in-url
Suppose this is my URL:
https://stackoverflow.com/questions/ask/question1.xml
Currently in my UrlMappings.groovy I have `
"/$Question/$ask/$question1"(controller:"somecontroller")` to handle the request.
If my URL changes to:
https://stackoverflow.com/questions/ask/askAgain/question1.xml
my URL mapping cannot handle it.
Is there a way I can get ask/askAgain to be referenced by $ask in my urlmapping.groovy?
This is what I did to get around this.
I changed my URLMapping to
"/$Question/$ask**"(controller:"somecontroller")
If my URL is :
`http://stackoverflow.com/questions/ask/askAgain/question1.xml`
So now, $ask** = ask/askAgain/question1.xml
Then, If I want to remove question1.xml from that URL. I can use Regex to get rid of it.
You will have to provide 2 mappings:
"/$Question/$ask/$question1"(controller: "somecontroller")
"/$Question/$ask/$askAgain/$question1"(controller: "somecontroller")
In my view I need to draw full URL. Like this:
http://hostename.com/default/url
When I try to use $this->url('default', array(1,2,3)) I get only /index/get/. Is there any Zend method to het host name or I have to use $_SERVER['HTTP_HOST'] instead?
You can use the option force_canonical on the router. All router options go into the third parameter of the url helper:
url($route, $params, $options)
So you can so something like this:
$this->url('myroute', array('id' => 123), array('force_canonical' => true))
I found this article with some interesting ways:
1) without parameters use an empty array:
// Using a route with the name "register" and the route "/register"
echo $this->url('register', array(), array('force_canonical' => true));
// Output: http://mydomain.com/register
2) note the differences between:
echo $this->serverUrl();
// Output: http://mydomain.com
and
// Current URL: http://mydomain.com/register
echo $this->serverUrl(true);
// Output: http://mydomain.com/register
3) starting from the route
// The "register" route has the following route: /register
echo $this->serverUrl($this->url('register'));
// Output: http://mydomain.com/register
There is a Zend\View\Helper\ServerUrl to create full url in zend view.
Try below code in your view template.
<?php echo $this->serverUrl()?>
If you want to set base URL globally, you can do it using onBootstrap method:
$e->getApplication()->getMvcEvent()->getRouter()->setBaseUrl($baseUrl);
In this case Navigation helpers would also use it.
To fetch current base URL use ServerUrl helper as described in this thread:
$serverUrl = $e->getApplication()->getServiceManager()->get('ViewHelperManager')->get('ServerUrl');
$baseUrl = $serverUrl->__invoke();