double slash in URLs. - zend-framework

Zend Route issue.
Normally it works fine.
http://www.example.com/course-details/1/Physics-Newtons-Law
But if I type in an extra slash in the url, the noauthAction of my Error controller gets called.
Example of URL's that are not working.
http://www.example.com/course-details//1/Physics-Newtons-Law
http://www.example.com/course-details/1//Physics-Newtons-Law
Is there something I need to set in the route definition to allow extra slashes?
Routing in application.ini
resources.router.routes.viewcourse.route = "/course-details/:course_id/:title"
resources.router.routes.viewcourse.defaults.controller = course
resources.router.routes.viewcourse.defaults.action = view
resources.router.routes.viewcourse.defaults.title =
resources.router.routes.viewcourse.reqs.course_id = "\d+"

You could use a controller plugin to fix common URL typos.
/**
* Fix common typos in URLs before the request
* is evaluated against the defined routes.
*/
class YourNamespace_Controller_Plugin_UrlTypoFixer
extends Zend_Controller_Plugin_Abstract
{
public function routeStartup($request)
{
// Correct consecutive slashes in the URL.
$uri = $request->getRequestUri();
$correctedUri = preg_replace('/\/{2,}/', '/', $uri);
if ($uri != $correctedUri) {
$request->setRequestUri($correctedUri);
}
}
}
And then register the plugin in your ini file.
resources.frontController.plugins.UrlTypoFixer = "YourNamespace_Controller_Plugin_UrlTypoFixer"

Related

CodeIgniter allow hyphen in url?

I have tried the following, but unfortunately it does not work:
$route['request-guide'] = "request_guide";
In my application/core I created MY_Router.php, but this is also not working.
<?php defined('BASEPATH') || exit('No direct script access allowed');
class MY_Router extends CI_Router {
function _set_request ($seg = array())
{
// The str_replace() below goes through all our segments
// and replaces the hyphens with underscores making it
// possible to use hyphens in controllers, folder names and
// function names
parent::_set_request(str_replace('-', '_', $seg));
}
}
?>
Open file /application/config/routes.php and add following line in the route array.
$route['translate_uri_dashes'] = TRUE;
It will automatically translate your MY_CONTROLLER to MY-CONTROLLER or in small letters.

HHVM - Rewrite rules for clean URLS

I have links like this - http://example.com/index.php?q=about and I want to make them look like this - http://example.com/about
Currently I am using the Rewrite Rules
VirtualHost {
* {
Pattern = .*
RewriteRules {
dirindex {
pattern = (.*)/$
to = index.php/$1
qsa = true
}
}
}
}
If I visit http://example.com/about I am getting a 404 File Not Found
I am doing this for Drupal. Guidelines for clean urls : https://drupal.org/getting-started/clean-urls
The issue can be resolved using the VirtualHost, but the server module of HHVM is depreciated now, and you are encouraged to use fastcgi over apache/nginx. I will put an answer for VirtualHost, but if needed, can update with an nginx alternative.
First, make sure that your SourceRoot is correct:
Server {
Port = 9000
SourceRoot = /home/myuser/www
DefaultDocument = index.php
}
Now, for the rule, this should potentially work:
VirtualHost {
* {
Pattern = .*
RewriteRules {
* {
pattern = (.*)$
to = index.php/$1
qsa = true
}
}
}
}
If you want the query to work exactly as you are intending it to, replace the inner pattern with this:
* {
pattern = /(.*)
to = index.php?q=$1
qsa = true
}
I have tested these both, and they work well. If you are still facing an issue, the issue may be potentially with your setup. Make sure you enable Error and Access logging .

TYPO3: Parse current url into variable

i know how i get the current URL with typoscript, but i dont know how i can parse this url into a variable so i can use and work with it.
temp.getUrl = TEXT
temp.getUrl.typolink {
parameter.data=TSFE:id
returnLast=url
}
This example returns me an url segment like 'This/is/just/a/test.html', so long – perfect!
Now i try to save this url into an Variable like
temp.getUrl = TEXT
temp.getUrl.typolink {
parameter.data=TSFE:id
returnLast=url
}
wiredMindsCompleteUrl < temp.getUrl
This results everytime just with 'TEXT' :( i kinda depressed.
Please help :)
The question is, where do you want to use it.
If you want to use it in different places in TypoScript you can f.e. render it into stdWrap.append / stdWrap.prepend of your links.
myMenu = HMENU
myMenu ...
myMenu.stdWrap.append < temp.getUrl
You could just put it into an Register:
page.1.LOAD_REGISTER
page.1.getUrl < temp.getUrl
and f.e. use your register in the tilte-Tag of an image:
lib.MyImage = IMAGE
lib.MyImage.file = ...
lib.MyImage.titleText.data = REGISTER:getUrl
lib.MyImage.tilteText.noTrimWrap = | makes no sense (IMHO:) ||
If you need it in your extension, just use it with cObjGetSingle.
plugin.tx_yourextension_pi1.getUrl < temp.getUrl
Inside your extension use it via
function main($content, $conf) {
$this->conf = $conf;
return $this->cObj->cObjGetSingle($this->conf['getUrl'], $this->conf['getUrl.'], 'getUrl');
}
Side note: use lib.getUrl instead of temp.getUrl, otherwise you can get in trouble with non-cached TypoScript parts.

Zend Framework Rerouting for Friendly SEO URL?

I don't even understand where to start using the documentation and it's instructions. A little dumbfounded.
I have the URL : http://www.site.com/test/view/?aid=155 right now.
I want it to show up as http://www.site.com/test/155 (Using controller "test" and action "view" with parameter aid as 155)
and for future learning experiences, how would I do http://www.site.com/madeupname/155
Where would I start? What file?
What do I put in it?
Please and thank you!!!!!
It's not that hard to do, especially if you use an .ini file for your routes.
Create a routes.ini file inside of your /site/application/configs folder.
For example :
[production]
routes.home.route = /home/
routes.home.defaults.controller = index
routes.home.defaults.action = index
routes.login.route = /login/:username/:password
routes.login.defaults.controller = index
routes.login.defaults.action = login
routes.login.defaults.username = username
routes.login.defaults.password = password
and then bootstrap it
(inside bootstrap.php, add this)
/*
* Initialize router rewriting via .ini file.
*/
protected function _initRewrite()
{
$router = Zend_Controller_Front::getInstance()->getRouter();
$router->addConfig(new Zend_Config_Ini(APPLICATION_PATH. "/configs/routes.ini",
'production'), 'routes');
}
You could then access the login page with www.site.com/login/yourname/yourpass
or get to the home page via www.site.com/home
http://www.devpatch.com/2010/02/load-routes-from-routes-ini-config-file-in-zend-application-bootstrap/
http://framework.zend.com/manual/en/zend.controller.router.html

Call TYPO3 plugin from other plugin's body

I need to call typo3 plugin from other plugin's body and pass its result to template. This is pseudo-code that describes what I want to achieve doing this:
$data['###SOME_VARIABLE###'] = $someOtherPlugin->main();
$this->cObj->substituteMarkerArray($someTemplate, $data);
Is it possible?
Thanks!
It doenst work if you use the whole pi construct, e.g. for links, marker function etc, and the TSFE Data can be corrupted.
Dmitry said:
http://lists.typo3.org/pipermail/typo3-english/2008-August/052259.html
$cObjType = $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_rgsmoothgallery_pi1'];
$conf = $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_rgsmoothgallery_pi1.'];
$cObj = t3lib_div::makeInstance('tslib_cObj');
$cObj->start(array(), '_NO_TABLE');
$conf['val'] = 1;
$content = $cObj->cObjGetSingle($cObjType, $conf); //calling the main method
You should use t3lib_div:makeInstance method.
There is a working example from TYPO3's "powermail" extension.
function getGeo() {
// use geo ip if loaded
if (t3lib_extMgm::isLoaded('geoip')) {
require_once( t3lib_extMgm::extPath('geoip').'/pi1/class.tx_geoip_pi1.php');
$this->media = t3lib_div::makeInstance('tx_geoip_pi1');
if ($this->conf['geoip.']['file']) { // only if file for geoip is set
$this->media->init($this->conf['geoip.']['file']); // Initialize the geoip Ext
$this->GEOinfos = $this->media->getGeoIP($this->ipOverride ? $this->ipOverride : t3lib_div::getIndpEnv('REMOTE_ADDR')); // get all the infos of current user ip
}
}
}
The answer of #mitchiru is nice and basically correct.
If you have created your outer extension with Kickstarter and you are using pi_base then there is already an instance of tslib_cObj and the whole construct becomes simpler:
// get type of inner extension, eg. USER or USER_INT
$cObjType = $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_innerextension_pi1'];
// get configuration array of inner extension
$cObjConf = $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_innerextension_pi1.'];
// add own parameters to configuration array if needed - otherwise skip this line
$cObjConf['myparam'] = 'myvalue';
// call main method of inner extension, using cObj of outer extension
$content = $this->cObj->cObjGetSingle($cObjType, $cObjConf);
Firstly, you have to include your plugin class, before using, or outside your class:
include_once(t3lib_extMgm::extPath('myext').'pi1/class.tx_myext_pi1.php');
Secondly in your code (in the main as example)
$res = tx_myext_pi1::myMethod();
This will work for sure (I've checked this): http://lists.typo3.org/pipermail/typo3-english/2008-August/052259.html.
Probably Fedir's answer is correct too but I didn't have a chance to try it.
Cheers!