I was wandering which solution is better to use in Yii framework,
1) Redirecting page from somethingController.php
$this->redirect(array($this->id."/something"));
|| or
2) Creating Url
$this->createUrl($this->id."/something");
in view using contoroller & action you need.
Or maybe there is a better solution?
Thanks
It like ask what is better miles or pounds?. That functions are very different.
You need to use redirect when need to change page without user action in some conditions, for example in controller:
if($money==0)
{
$this->redirect(array('alerts/notEnoughMoney'));
}
If you want to generate address what will used for example in html links, then you need to use createUrl, because it will:
Avoid unnecessary step with redirect
Better for SEO, and will be more user friendly
Better for customizing
You can use createUrl in view, for example:
<?php
$link = $this->createUrl(array('user/profile'));
?>
My Profile
In any case, if you using redirects what visible for search bots you need to add second parameter:
$this->redirect(array('alerts/notEnoughMoney'),301);
----------------------------------------------^^^^
With this parameter bot will understand what this next page is permanent and will cache it as "main".
$this->createUrl($this->id."/".$this->action->id);
is the better because it will work with URL manager also and give rewrite urls.
Related
I am building an TYPO3 extension with Extbase and want to store data which I get via HTTP GET.
Now I struggle with possibility to use a browser to access the action controller.
The plugin is implemented into page 102
The extension key is xyzlist
the Plugin Name is xyzlistdb
The controller name is PlaylistController
The action is getAction
The domain name is sub.domain.de
In the PlaylistController.php is under getAction only
error_log("GetAction",0);
to figure out, if the browser url goes to the getAction.
Here the URL I am using
http://sub.domain.de/index.php?id=102&tx_xyzlist_xyzlistdb[controller]=playlist&tx_xyzlist_xyzlisdb[action]=get
In the browser I am using '&' instead of only '&'
But if I only use '&', it also not access the Get action
But I don't get any message in the log file!
What I am doing wrong?
Here you have multiple possibilities...
First, you can disable [FE][pageNotFoundOnCHashError] (Install-Tool), so you dont get an 404 on invalid cHash. This is globaly for you site for all plugins. Its not the secure way.
Second, you can set plugin.tx_xyzlist_xyzlistdb.features.requireCHashArgumentForActionArguments = 0 in your typoscript to disable the pageNotFoundOnCHashError for you plugin.
Last, you can add your variables to [FE][cHashExcludedParameters] (Install-Tool), so that your variables are not included in the cHash calculation.
To get the correct link, you will have to use typolink. Probably the easiest way to generate a link to a plugin action is to use f:uri.action in a template like this:
<f:uri.action pageUid="102" extensionName="xyzlist" pluginName="xyzlistdb" action="get" />
https://docs.typo3.org/other/typo3/view-helper-reference/9.5/en-us/typo3/fluid/latest/Link/Action.html
Write first letter of your controller name capitalized.
http://sub.domain.de/index.php?id=102&tx_xyzlist_xyzlistdb[controller]=Playlist&tx_xyzlist_xyzlisdb[action]=get
Also do not turn off cHash without a good reason. That problem is not a reason at all.
Jonas mentioned to generate a link to your action with:
<f:uri.action pageUid="102" extensionName="xyzlist" pluginName="xyzlistdb" action="get" />
It is indeed a good and time saving practice.
When I click on "Laxatives"
Then I should see the '/laxatives" page
For the above behat scenario how can i validate or make sure that it redirects to correct url.
For now when i run this it redirects to correct page, but if incase it does not how will i validate through script.Kindly help
when there is no big amount of links you're testing, you can use switch statement to specify expected URL for each option.
Otherwise I would suggest to create some class acting like translations, so when you request Laxatives, it will tell you, that "/laxatives" string must be present within the page URL. You can then specify this "translations" in some JSON or CSV file.
Then just use: $this->assertSession()->addressMatches($regex); where the regex will be set by switch statement or loaded by the class I mentioned.
The simplest and easiest way of achieving is this:
Given I am on 'home-page'
When I follow 'link-to-laxatives-page'
Then I should see 'Welcome to Laxatives'
So Welcome to Laxatives is a simple text which presents in /laxatives page.
Note: If there is a text which is completely unique to the page then use that otherwise use something else.
OTHER OPTIONS:
You can use getCurrentUrl() in your FeatureContext.
Use already build-in step which is in MinkContext
I'm using typo3 and realurl.
In my extension I generate some ID's (next and previous page) and everything works fine up to this point. An example link looks like:
/index.php?id=12
The link takes the visitor to the specific page, but this link is in the url as well. Of course I generate this linke exactly like this:
$GLOBALS['TSFE']->baseURL . "index.php?id=" . $banner->getPrevious();
So, it is exactly what i expected. But how can i turn this url into a seo-friendly URL?
Is there something like $realUrl->createUrlFromId()? :P
I checked the manual, looked in some forums, but 99% of the time it is something related to TypoScript, which I don't need (from my point of view) in this case.
Edit:
Here is the .htaccess:
http://pastebin.com/DBXjLYjp
Thank you in advance
RealURL hooks into several core methods to generate links, and manipulates the result to be a speaking URL. So, no, it does not offer an own method, but extends existing ones.
You don't use a link generation, but build it by yourself. RealURL therefore can not access your link.
The htaccess only converts speaking urls back into GET-params.
Use a method like pi_linkToPage, a link viewhelper, or a TypoScript typolink to generate a link.
$myLink1 = $this->pi_linkToPage('example', 42);
$myLink2 = $this->cObj->typolink('example', array(
'parameter' => 42,
));
So - I'm new to Laravel and we're using version 3.
I have a home page setup & working - say http://dev.mywebsite.com
Now I want to click a link on the page and redirect to a nice SEO friendly URL, but pass in the variables. In straight PHP this is simple - I can make http://dev.mywebsite.com/vacancies/town/page2 rewrite as http://dev.mywebsite.com/?where=town&page=2
But I can't get this to work in Laravel.
I know the full answer is to create controllers & views, but I have all the logic for the display in an included file so don't really want to change... is there any way to do this using either routes or mod-rewrite?
Thanks
Although I strongly recommend you to make a view with that file, you can still use PHP's Output Control to avoid messing with Laravel's rendering flow:
Route::get('your-nice-url-here', function() {
ob_start();
include 'your-raw-php-here';
return Response::make(ob_get_clean());
});
I have a quick question i hope you guys can answer, i've got a search system that uses POST to do searches, now i want to track queries using Google Analytics but it requires using GET url parameters to pull parameters out the URL, what i don't want to do is rewrite the entire search system to use GET instead of POST. Is there any way around this? I was thinking maybe i can make a GET call to a new page from the page that recieves the search POSTs, but i don't want it to redirect, i merely want it to "hit" the url without actually redirecting?
Is this possible?
Any other solutions would also be appreciated.
Thanks for the help
You can specify an abritrary URL when you add your GA code. For example, all our different checkout pages go through validate.php, so this is the URL that the person would see, however, we put in some extra code to give a specific tracking URL to google.
For example:-
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-XXXXX-1");
pageTracker._setDomainName("example.com");
pageTracker._trackPageview("/checkout/login/");
} catch(err) {}
</script>
Would make google track this as being /checkout/login/ even though the page in the browser actually shows /validate.php
You can output (as we do) this page variable from different PHP variables
$searchterm = $_POST['search'];
echo 'pageTracker._trackPageview("/search/' . urlencode($searchterm) . '");';
Sure, use the apache mod_rewrite module to create a fancy, seo friendly url and pass the user keywords in the url.
Something like "www.yoursite.com/search/what+a+user+searches+for/"
In a .htaccess file you create a rule
RewriteRule ^search/(.*)/$ /search.php?keywords=$1
You're orignal script keeps working with your postvalues and you provide an URL with GET variables. With explode("+", $_GET["keywords"]) you can extract the searchvalues.
With the array $_REQUEST you can access all request parameters GET and POST.
The only way you will be able to do this, is re-set the forms method to GET and just changed the $_POST requests to $_GET
Thats not such a huge change?
You should be able to do that with HTTPRequest:
http://php.net/manual/en/class.httprequest.php
You can just alter your Google Analytics code - see Tracking Custom Variables