Laravel variable to URL without changing url-route path - url

I'm new to laravel and am interested in adding a variable from a db to the end of my url without effecting the path. for example if a user logs in and has variable = hello assigned in the db the url will read http://app.com/home/hello. However I don't want the this to change where my routing, so its still looking at /home and not for /home/hello
I've tried to change the routing in web.php as follows:
Route::get('/home',function(){
return redirect('home/{{Auth::user()->variable}}');
});
Route::get('/home/{{Auth::user()->variable}}', 'HomeController#index');
But this seems messy and it's not pulling my variable from the db. I'm sure there's a better way I haven't been
able to find. I'm not looking for a complete solution, just a link to a tutorial or point in the right direction.

You should be able to do something like:
Route::get('/home',function(){
return redirect('home/'.Auth::user()->variable);
});
Route::get('/home/{variable}', 'HomeController#index');
Then the value of 'variable' would be available in your HomeController index method
public function index($variable) { ... }
https://laravel.com/docs/5.7/routing#route-parameters

Related

Get url of Orchard default pages

I am using orchard 1.9 and I am building a service in which I need to get current URL.
I have OrchardServices and from that I can get the URL like so:
_orchardServices.WorkContext.HttpContext.Request.Url.AbsolutePath;
This works like a charm for pages/routes that I have created but when I go to the Login or register page (/Users/Account/LogOn) the absolute URL is / and I can't find anyway to get the URL or at least any indication that I am in the LogOn or Register.
Anyone knows how I could get the full url?
If I understand what your're asking, you could use the ItemAdminLink from the ContentItemExtension class.
You will need to add references to Orchard.ContentManagement, Orchard.Mvc.Html and Orchard.Utility.Extensions, but then you will have access to the #Html and #Url helpers.
From there you will have the ability to get the link to the item using:
#Html.ItemDisplayLink((ContentItem)Model.ContentItem)
The link to the item with the Url as the title using: #Url.ItemDisplayUrl((ContentItem)Model.ContentItem)
And you should get the same for the admin area by using these:
#Html.ItemAdminLink((ContentItem)Model.ContentItem)
#Url.ItemAdminUrl((ContentItem)Model.ContentItem)
They will give you relative paths, e.g. '/blog/blog-post-1', but it sounds like you've already got a partial solution for that sorted, so it would be a matter of combining the two.
Although I'm sure there are (much) better ways of doing it, you could get the absolute URL using:
String.Format("{0}{1}", WorkContext.CurrentSite.BaseUrl, yourRelativeURL);
...but if anyone has a more elegent way of doing it then post a comment below.
Hope that helps someone.

How can I retrieve an id from the url in Coldfusion?

I'm updating a site and am struggling to find a way to get an id from the URL. For example I have this:
http://some.html/search.cfm?id=9900000000301
How do I get the id value "9900000000301" from the URL in Coldfusion8?
I have tried url.id plus all sorts of *cgi.query_string* variations, but the number is still out of reach :-(
Thanks for help!
EDIT:
If I dump the URL struct, I'm getting this:
catch - struct
TYPE: default
VALUE: search
Which is not saying much to me.
The url.id should work just fine.
Url.Id will work - with one exception.
If you have created a variable called Url, it is possible (in Adobe CF) to "hide" the Url scope, and thus not be able to access it.
For example, if you have a function with an argument called url, referring to url inside that function will refer to Arguments.Url, not the Url scope. If this is the case, you need to rename the argument to be able to access the proper Url scope.
(Alternatively, switch to a better CFML engine where scope names always takes precedence over unscoped variables, and thus scopes cannot be hidden.)
Depending on how you are looking to use the data, here are two examples. The first checks to see if it was defined and the second sets a variable to the value.
<cfif isDefined("URL.id")>
<cset myVariable = URL.id>
</cfif>
Hope this helps!

Symfony use_javascript() routing issue

i am using symfony 1.4.11; use_helper('Url').
On using link_to('new',course/course/type/new),
the url it show is ../backend_dev/backend_dev/Course/course/type/new
instead of
../backend_dev/Course/course/type/new.
Same issue exist for form_tag also.
Edit
Above issue was solved.By setting no_script_name: true at config and clearing cache.
But image_tag(),use_stylesheet() and use_javascript() gives path as for example
use_javascript('jquery-1.6.1.min.js')
==>../web/backend_dev/js/jquery-1.6.1.min.js
instead of
use_javascript('jquery-1.6.1.min.js') ==>../web/js/jquery-1.6.1.min.js
Any help appreciated.
Hard to say without your full routing.yml but the one thing i see is that your internal_uri should be expressed as an abs url with a query string like:
link_to('new','/Course/course?type=new');
Note the forward slash at the beginning. Also the module name should be the real module name, not the routed one so if the maodule is /apps/backend/modules/Course then the module in the internal URI should be Course not course same with the action name.
If the route is named then you should use one of the following:
link_to('new','#routename?type=new');
OR
link_to('new','routename', array('type'=>'new'));

Handling question mark in url in codeigniter

I am using a payment method which on success returns a url like mysite/payment/sucess?auth=SDX53641sSDFSDF, but since i am using codeigniter, question marks in url are not working for me.
I tried routing but it didnt work. As a final resort i created a pre system hook and unset the GET part from the url for with i had to set
$config["uri_protocol"] = "REQUEST_URI";
It worked that way but all other links in my site were not working as intended, tried changing the uri_protocol but could not make it work by any means.
So basically my problem is handling the ?auth=SDFSEFSDFXsdf5345sdf part in my url, whenever the paypment method redirects to my site with the url mentioned above, it gets redirected to homepage instead of the function inside controller.
How can i handle this, i'm using codeIgniter 1.7 version, and couldnt find any way.
Please suggest some solution.
I think I would extend the core URI class, by creating new file at application/libraries/MY_URI.php which will extend the CI_URI class, then copy the _fetch_uri_string method and here you can add your logic if the $_SERVER['QUERY_STRING'] is present:
class MY_URI extends CI_URI
{
function __construct()
{
parent::CI_URI();
}
//Whatever this method returns the router class is using to map controller and action accordingly.
function _fetch_uri_string()
{
if(isset($_SERVER['QUERY_STRING']) AND !empty($_GET['auth']))
{
//Do your logic here, For example you can do something like if you are using REQUEST_URI
$this->uri_string = 'payment/success/'.$_GET['auth'];
return;
//You will set the uri_string to controller/action/param the CI way and process further
}
//Here goes the rest of the method that you copied
}
}
Also please NOTE that you must do security check of your URL and I hope this works for you, otherwise you can try extending the CI_Router class or other methods (experiment little bit with few methods, though the _set_routing is important). These 2 classes are responsible for the intercepted urls and mapping them to controller/action/params in CI.
I believe this thread holds the answer.
Basically add
$config['enable_query_strings'] = TRUE;
to your config.php
hope this will help you ! no need to change htaccess,just change your code.
redirect(base_url()."controller_name/function_name");
Looking at the example code in the Stripe docs:
https://stripe.com/docs/payments/checkout/set-up-a-subscription
one might conclude that you can only retrieve a checkout_session_id as a named GET parameter like this:
'success_url' => 'https://example.com/success?session_id={CHECKOUT_SESSION_ID}',
After playing around with .htaccess and config settings (as in previous answers) and finally getting it to work, it suddenly dawned on me that the DEVELOPER is in control of the success_url format, not Stripe. So one can avoid all the problems with a GET parameter by specifying the success url in the normal, clean Codeigniter format, like this:
'success_url' => 'https://example.com/success/{CHECKOUT_SESSION_ID}',
In my routes file, the incoming CHECKOUT_SESSION_ID string is passed to the Subscription controller's checkout_success method with this route:
$route['success/(:any)'] = 'subscription/checkout_success/$1';
The method accepts the $checkout_session_id like this:
function checkout_success($checkout_session_id)
{
// Do something with the $checkout_session_id...
}
I'm new to Stripe Checkout but this seems to simplify the integration without breaking Codeigniter's GET processing rules.

Codeigniter _remap function

Please help I want to use first URI segment into my CodeIgniter website.
Like when I open these url they opens my profile:
http://www.facebook.com/buddyforever
or
http://www.myspace.com/zarpio
How can I do this with CodeIgniter? I checked _remap function but first coming controller how to hide controller?
You can do this using the URL routing of codeigniter...
If you want your URL to be http://www.mydomain.com/zarpio and you want it to refer to your_controller, then do the following.
/config/routes.php
$route['(.*)'] = "your_controller/$1"; // Now, `zarpio` will be passed to `your_controller`
You can access it in your controller like this...
$my_name = $this->uri->rsegment(2);
However I do not suggest this way of configuring URLs. A better way would be...
$route['users/(.*)'] = "your_controller/$1";
This way, you're just renaming your controller name your_controller to users.
If you want to access profile of a user, you can do it like this...
$route['users/profile/(.*)'] = "another_controller/method/$1";
$route['users/(.*)'] = "your_controller/$1";
Consider the order of routing. Since you wrote users/(.*) in your route, it will match users/zarpio as well as users/profile/zarpio, and route both of them to your_controller/$1, which in the case of profile will give you a 404 page not found error. That is why you need to write users/profile/(.*) before users/(.*) in your routing configuration.
More information in codeigniter URI class documentation

Resources