CodeIgniter allow hyphen in url? - codeigniter-3

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.

Related

Typoscript: how do I add a parameter to all links in the RTE?

I want to add a parameter to all links entered in the RTE by the user.
My initial idea was to do this:
lib.parseFunc_RTE.tags.link {
typolink.parameter.append = TEXT
typolink.parameter.append.value = ?flavor=lemon
}
So for example:
http://domain.com/mypage.php
becomes
http://domain.com/mypage.php?flavor=lemon
which sounds great -- as long as the link does not already have a query string!
In that case, I obviously end up with two question marks in the URL
So for example:
http://domain.com/prefs.php?id=1234&unit=moon&qty=300
becomes
http://domain.com/prefs.php?id=1234&unit=moon&qty=300?flavor=lemon
Is there any way to add my parameter with the correct syntax, depending on whether the URL already has a query string or not? Thanks!
That would be the solution:
lib.parseFunc_RTE.tags.link {
typolink.additionalParams = &flavor=lemon
}
Note that it has to start with an &, typo3 then generates a valid link. The parameter in the link also will be parsed with realURL if configured accordingly.
Edit: The above solution only works for internal links as described in the documentation https://docs.typo3.org/typo3cms/TyposcriptReference/Functions/Typolink/Index.html
The only solution that works for all links that I see is to use a userFunc
lib.parseFunc_RTE.tags.link {
typolink.userFunc = user_addAdditionalParams
}
Then you need to create a php script and include in your TS with:
includeLibs.rteScript = path/to/yourScript.php
Keep in mind that includeLibs is outdated, so if you are using TYPO3 8.x (and probably 7.3+) you will need to create a custom extension with just a few files
<?php
function user_addAdditionalParams($finalTagParts) {
// modify the url in $finalTagParts['url']
// $finalTagParts['TYPE'] is an indication of link-kind: mailto, url, file, page, you can use it to check if you need to append the new params
switch ($finalTagParts['TYPE']) {
case 'url':
case 'file':
$parts = explode('#', $finalTagParts['url']);
$finalTagParts['url'] = $parts[0]
. (strpos($parts[0], '?') === false ? '?' : '&')
. 'newParam=test&newParam=test2'
. ($parts[1] ? '#' . $parts[1] : '');
break;
}
return '<a href="' . $finalTagParts['url'] . '"' .
$finalTagParts['targetParams'] .
$finalTagParts['aTagParams'] . '>'
}
PS: i have not tested the actual php code, so it can have some errors. If you have troubles, try debugging the $finalTagParts variable
Test whether the "?" character is already in the URL and append either "?" or "&", then append your key-value pair. There's a CASE object available in the TypoScript Reference, with an example you can modify for your purpose.
For anyone interested, here's a solution that worked for me using the replacement function of Typoscript. Hope this helps.
lib.parseFunc_RTE.tags.link {
# Start by "replacing" the whole URL by itself + our string
# For example: http://domain.com/?id=100 becomes http://domain.com/?id=100?flavor=lemon
# For example: http://domain.com/index.html becomes http://domain.com/index.html?flavor=lemon
typolink.parameter.stdWrap.replacement.10 {
#this matches the whole URL
search = #^(.*)$#i
# this replaces it with itself (${1}) + our string
replace =${1}?flavor=lemon
# in this case we want to use regular expressions
useRegExp = 1
}
# After the first replacement is done, we simply replace
# the first '?' by '?' and all others by '&'
# the use of Option Split allow this
typolink.parameter.stdWrap.replacement.20 {
search = ?
replace = ? || & || &
useOptionSplitReplace = 1
}
}

German umlauts not showing in Zend Form

I've been facing a problem with Zend Form, for some reason words that have german special characters do not show in the dropbox.
for the form I'm using this partial code:
$country_to = new Zend_Form_Element_Select('country_to');
$country_to->setLabel('Traveling To (Country)')
->addMultiOptions($this->country_list);
And I'm getting it from the DB like this:
protected $country_list = array();
protected function getCountryValues()
{
$mapper = new Application_Model_Mapper_Resource();
$resources = $mapper->fetchAllCountries();
$this->country_list[''] = '';
foreach($resources as $resource){
$this->country_list[$resource->getName()] = $resource->getName();
}
}
and the result I'm getting is this:
I dumped the country_list and it actually contains all data but it's not showing in the form!
I found the solution, it was pretty simple. I need to disable the default escaping by zend.
I simply added this to the beginning of the form and it worked:
$this->getView()->setEscape('stripslashes');

double slash in URLs.

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"

How to add two numbers in sugar crm

I made module addition and in this made three fields amount1_c, amount2_c and total_amount_c to add the two numbers and display the result in the third field. I done coding in the logic looks here is my code
<?
$hook_version = 1;
$hook_array = Array();
$hook_array['before_save'] = Array();
$hook_array['before_save'][] = Array(1,'calculate_field', 'custom/modules/cases/LogicHookMath.php','LogicHookMath', 'calculate_field');
?>
and made one more file logic hook math. here is my code for
<?php
class LogicHookMath {
function calculate_field(&$bean, $event, $arguments) {
$field1 = $bean->amount1_c;
$field2 = $bean->amount2_c;
$field3 = $field1 + $field2;
$bean->amount_total_c = $field3;
}
}
?>
but still i did not get any result. Please help me out for this.
The code looks correct.
Some common "mistakes" when custom logic hooks are not working:
Make sure, the custom logic hook has the correct name (LogicHookMath.php)
Make sure, that the $bean variable is prefixed with &, so the variable is passed as a reference
Make sure the logic_hooks.php and the LogicHookMath.php files are readable by the web server user
The entire custom directory should also be writeable for the web server user
If the above does not help, try logging the progress to the sugarcrm.log using $GLOBALS['log']->info( "Value 3: ". $field3); in the custom logic hook.

How should I redirect users in a formmail script?

So I'm using a basic formmail script. Within the script I'm using a redirect variable. The value of the redirect is something like:
http://www.mysite.com/NewOLS_GCUK_EN/bling.aspx?BC=GCUK&IBC=CSEE&SIBC=CSEE
When the redirect action happens however, the URL appears in the browser as:
http://www.mysite.com/NewOLS_GCUK_EN/bling.aspx?BC=GCUK&IBC=CSEE&SIBC=CSEE
You can see the & characters are replaced with &
Is there any way to fix this?
Maybe you can edit the script with a string substitution:
$myRedirectURL =~ s/\&/\&/g;
Or perhaps look in the script where the opposite substitution is taking place, and comment out that step.
HTML::Entities's decode_entities could decode this for you:
$redirect_target = decode_entities($redirect_target);
But passing the destination URL as HTTP argument (e.g. hidden form field) is dangerous (as #Sinan Ünür already said in the comments). Better store the target URL within your script and pass a selector from the form:
if ($selector eq 'home') { $target_url = 'http://www.foo.bar/'; }
elsif ($selector eq 'bling') { $target_url = 'http://www.foo.bar/NewOLS_GCUK_EN/bling.aspx'; }
else {
$target_url = 'http://www.foo.bar/default.html'; # Fallback/default value
}
Using a Hash would be shorter:
my %targets = {
home => 'http://www.foo.bar/',
bling => '/NewOLS_GCUK_EN/bling.aspx',
};
$target_url = $targets{$selector} || '/default_feedback_thanks.html';