On my site, when I call $this->baseUrl() in a view, it returns an empty string. I would expect it to return e.g. http://www.foobar.com/. Do I need to manually set base url?
In manual to Zend_Application_Resource_Frontcontroller - configuration keys, I have just found this:
baseUrl: explicit base URL to the application (normally auto-detected)
Any ideas why it is not autodetected for me?
The baseUrl() helper returns the path to your Zend Application.
Use the serverUrl() helper for the hostname.
Did you set the baseurl in your application.ini?
resources.frontController.baseUrl = "/subdir"
Manual
Related
In web2py, I want to set up a controller that redirects for an html view but provides a json response for a json view, e.g.
http://mysite/page.html/1234 -> redirects to http://www.google.com/q=mydata
http://mysite/page.json/1234 -> returns JSON {'1234':'my data'}
(this example assumes I have a db query that returns 'mydata' for id=1234)
I can't immediately see how to do this, as the redirect() function is called in the controller, but the decision about json or html seems to be made later, once a dict() is returned from the controller
In the controller you can use request.extension to decide whether to redirect() or return response.json(my_data).
I also found that you can set {{redirect('http://site/{}'.format(data))}} in the .html view, and it will do a proper redirect within the html file itself (and set the correct content headers). In other words, the redirect function doesn't need to be called in the controller, if that's easier.
I use RealUrl for my website. In my certain extension, I require to decode the url created by RealUrl to the normal TYPO3 url format.
Example:
To my controller I get this link : typo3website/feature/number/123 , now how do I convert this to typo3website/index.php?id=99&number=123
The RealUrl does not use namespace, and hence i'm unable to understand how to create an instance of the class tx_realurl.
I tried using require_once(PATH_typo3conf.'ext/realurl'.'/class.tx_realurl.php'); and creating new instance of tx_realurl, but gives a class not found error.
If RealURL is configured properly and the link is generated with the uriBuilder or the ActionViewHelper, you don't need to take care of that. If we take your example and you configured RealURL to use typo3website/feature/number/123 for index.php?id=99&tx_yourext[number]=123, you can use this as argument for your action:
public function showAction($number) {
}
You can also access all arguments from a controller action by using
$this->request->getArguments()
Is there a way to dynamically add a slash to your rest url?
e.g. I want to be able to generate the following rest urls in one resource.
rest/blogpost/1
rest/blogpost/1/allInfo
given the resource below, i can achieve my first url. But is there a way to make the second url with /allInfo (optional in same lResource).
lResource = $resource("../rest/blogpost/:blogId", {
Or do I need a second resource like this?
lResource = $resource("../rest/blogpost/:blogId/allInfo", {
The problem with the second $resource is that allInfo isn't optional
If you make your second argument optional using the : you can make it to work.
var lResource = $resource("rest/blogpost/:blogId/:allInfo");
lResource.query({});
lResource.query({blogId:123});
lResource.query({blogId:123,allInfo:'allInfo'});
See my fiddle http://jsfiddle.net/cmyworld/NnHr4/1/ ( See Console log)
I am trying to figure out how to do a redirect within a controller action in Play (2.0) using Scala.
The redirect using
Redirect(routes.Application.index)
works just fine.
What I cannot figure out from the docs, API, or Google is how to add parameters to the call.
I am coming from Grails where this could be done easily as follows:
redirect action: "index", params: ["key": "value"]
.
The only way I have found is to call Redirect using a string url and a query string, which seems awkward.
Basically I would like to make use of Redirect(Call) somehow, but I do not how to create the Call object using reverse routing.
Am I missing something/not getting the concept in Play/Scala?
Thanks in Advance!
Ellou'
A route is just a function, so you can pass arguments as usual:
// Redirect to /hello/Bob
def helloBob = Action {
Redirect(routes.Application.hello("Bob"))
}
This snippet comes from http://www.playframework.org/documentation/2.0/ScalaRouting (at the bottom)
You can also avoid creating another function just for this in your controller. In your route config, you can simply add something like this:
GET /google #controllers.Default.redirect(to = "http://google.com")
Are there some proper Zend methods for:
a) receiving path to /public directory
b) receiving application url
Actually I'm using methods defined in Controller, but it feel right to use ready methods if they exits.
protected function _getApplicationUrl() {
return $_SERVER['SERVER_NAME'];
}
protected function _getPublicPath() {
return realpath(APPLICATION_PATH . '/../public/');
}
Regarding the application URL, Zend_Controller_Request_Http has a getRequestUri() method, but it deliberately (and somewhat frustratingly) excludes the scheme and hostname parts of the URL. In my apps I have resorted to grabbing $_SERVER['HTTP_HOST'] in the bootstrap and storing it in the registry so that I can use it later when constructing full URLs.
And from memory, no, there isn't any built-in method to get the location of the public folder, but the code you have is fine. Most apps I've seen define() all the paths in index.php, which I suppose is slightly safer (only because the path names get set sooner and become absolutely immutable) and ever so slightly faster, but lets not get into a debate about micro-optimizations! :-)
1) If your virtual host point to ZF /public then in View you can get path by helper method $this->baseUrl(); In controller $this->view->baseUrl(); Otherwise create your own helper and use it.
2) In controller $this->getRequest()->getHttpHost();
protected function _getPublicPath() {
chdir(APPLICATION_PATH);
return realpath("../public");
}
a) receiving path to /public directory
Built-in php-function getcwd() will give you the path to your site-host folder (ex. output "/home/my_cp/public_html/my_site.loc/www"). And then, you can construct whatever path you want.