I have a custom route controller that checks the database before returning view. that being said I'm not passing any parameters to this controller besides the first and never will. Is there a way to stop laravel from expecting a parameter? I'm getting this error:
mydomain/login ---- Works Fine
mydomain/login/sometext -- Throws error
"Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException"
/var/www/html/vendor/laravel/framework/src/Illuminate/Routing/RouteCollection.php
routes.php
Route::get('/', function(){return View::make('main.landing');});
Route::get('/{path}', array('uses' => 'RouteController#index'));
Then in my RouteController I take $path and query database to check if route exists and then displays the custom view.
Any help would be greatly appreciated!
Thanks!
You need to specify to the router that you want to allow slashes in your route parameter. You can do it like so:
Route::get('/{path}', array('uses' => 'RouteController#index'))->where('path', '(.*)');
This will allow any character.
By default route parameters do not accept slashes. You need to explicitly allow any characters in your path parameter:
Route::get('/{path}', array('uses' => 'RouteController#index'))
->where('path', '(.*)');
Related
I am trying to pass the signInSuccessUrl parameter dynamically to the widget page as an URL parameter. Unfortunately without success.
According to the gitkit forum (https://groups.google.com/d/msg/google-identity-toolkit/grF6C4CByEk/Dz4l2P-mTOwJ) this should work.
Am I missing something? Thank you.
That's what I tried:
The signin.html page showing the widget is configured like this:
JS Config:
var config = {
apiKey: '...',
idps: ["googleplus"],
//signInSuccessUrl:NOT SPECIFIED CAUSE WE PASS IT VIA URL,
oobActionUrl: '//127.0.0.1:8888/gwt/servlet/gitkit/email',
siteName: 'SN',
};
window.google.identitytoolkit.start(...);
Open browser and show Javascript console of browser
Enter the widget page url in browser:
http://127.0.0.1:8888/signin.html?signInSuccessUrl=127.0.0.1%3A8888%2Fgwt%2Fservlet%2Fgitkit%2Fsignedin%0A&o=dynamic
Continue with sign in...
This will not redirect to signInSuccessUrl but rather produce the error:
Uncaught Error: Configuration signInSuccessUrl is required.Si # gitkit.js:217Ik # gitkit.js:248(anonymous function) # gitkit.js:257(anonymous function) # gitkit.js:152(anonymous function) # gitkit.js:213Fc # gitkit.js:38h.dispatchEvent # gitkit.js:36zi # gitkit.js:210U.onReadyStateChangeEntryPoint_ # gitkit.js:208U.onReadyStateChange_ # gitkit.js:208
NOTE: if I set the signInSuccessUrl param in widget config, like:
signInSuccessUrl:"//127.0.0.1:8888/gwt/servlet/gitkit/signedin?o=hardcoded",
It will work but NOT use the signInSuccessUrl provided in the URL but the hardcoded one, i.e. the 'o' param in this example will not be overriden.
The reason it did not work was related to using the open scheme in oobActionUrl
'//127.0.0.1:8888/gwt/servlet/gitkit/email'
When using 'http://127.0.0.1:8888/gwt/servlet/gitkit/email' it did work.
the signInSuccessUrl in the widget configuration is a required field. You always have to provide it. The signInSuccessUrl parameter in the widget url if provided will override the config value. This makes sense since the signInSuccessUrl query parameter is optional and may not always be provided in the url. Try providing it in the config and then pass it in the url. It should work the way you want it to.
I try to use the following plugins in local mode:
s.Util.cookieRead https://marketing.adobe.com/resources/help/en_US/sc/implement/util_cookieread.html
s.Util.cookieWrite https://marketing.adobe.com/resources/help/en_US/sc/implement/util_cookiewrite.html
When I type in console i.e. s.Util.getQueryParam I take back the function which seems that the configuration in file it is allright.
s.Util.getQueryParam
AppMeasurement.a.Util.getQueryParam(c, b, d)
How ever when I go to add the example in plugin function
s.campaign = s.Util.getQueryParam("cid");
when I run my site I can't see anything of this plugin
Also when I use the
getNewRepeat https://marketing.adobe.com/resources/help/en_US/sc/implement/getNewRepeat.html
plugin it always shows me as New visitor.
Is there any special configuration I should make in order to make them to work properly?
// set a session cookie named foo to value 'bar'
s.Util.cookieWrite('foo','bar');
// look for cookie named 'foo' and return value if found, and assign it to prop1
s.prop1 = s.Util.cookieRead('foo');
I have this in my routes.conf file:
# SecureSocial routes
# Login page
GET /login securesocial.controllers.LoginPage.login
And then I have this in a Scala Controller file
val index = SecuredAction { implicit request =>
Redirect(routes.UserOps.watchlist)
// how do I go straight to /login? >|
}
Doing this takes me to a login page that has a red error bar saying "you must be signed in to view this page". If I access `localhost:9000/login' I get the login page without the error bar.
Normally I do a Redirect(routes.SomeControllerObject.ActionMethodName) but in this case the controller I need to access is in a plugin...
I feel like I'm missing something rather large here...
Update:
To reverse-route to an action in a plugin controller you need to provide the correct, full path to the plugin's routes class.
Redirect(securesocial.controllers.routes.LoginPage.login)
Original Answer
For reverse-routing I don't think it matters where the Controller is since Play is building that when the project compiles. From the documentation:
For each controller used in the routes file, the router will generate a ‘reverse controller’ in the routes package, having the same action methods, with the same signature, but returning a play.api.mvc.Call instead of a play.api.mvc.Action.
So this should work just as if LoginPage was a controller directly in your app.
Redirect(routes.LoginPage.login);
In order to show the message, you must have an item in the Flash. When you hit /login directly, there is no flash, so you won't see that message.
If you want to see that message:
Redirect(securesocial.controllers.LoginPage.login).flashing( ... )
I need the full path to a action inside my controller, to send it via email. How can I achieve something like {{ path('_route') }} from inside my controller but the full path?
Juan's answer is right if you want the local path. The absolute path — which is helpful to be send through email — needs extra parameter(s):
$url = $this->generateUrl('your_route_name', array(), true);
The third parameter indicates that the absolute path is to be generated.
If you want to use this URL in your view just add the $url to the response array in your action and use it.
Symfony 3+
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
$this->generateUrl('your_route_name', array('/* your route parameters */'), UrlGeneratorInterface::ABSOLUTE_URL);
Try the following:
$url = $this->generateUrl('your_route_name');
How can I build a block in Drupal which is able to show the node ID of the view page the block is currently sitting on?
I'm using views to build a large chunk of my site, but I need to be able to make "intelligent" blocks in PHP mode which will have dynamic content depending on what the view is displaying.
How can I find the $nid which a view is currently displaying?
Here is a more-robust way of getting the node ID:
<?php
// Check that the current URL is for a specific node:
if(arg(0) == 'node' && is_numeric(arg(1))) {
return arg(1); // Return the NID
}
else { // Whatever it is we're looking at, it's not a node
return NULL; // Return an invalid NID
}
?>
This method works even if you have a custom path for your node with the path and/or pathauto modules.
Just for reference, if you don't turn on the path module, the default URLs that Drupal generates are called "system paths" in the documentation. If you do turn on the path module, you are able to set custom paths which are called "aliases" in the documentation.
Since I always have the path module turned on, one thing that confused me at first was whether it was ever possible for the arg function to return part of an alias rather than part of system path.
As it turns out, the arg function will always return a system path because the arg function is based on $_GET['q']... After a bit of research it seems that $_GET['q'] will always return a system path.
If you want to get the path from the actual page request, you need to use $_REQUEST['q']. If the path module is enabled, $_REQUEST['q'] may return either an alias or a system path.
For a solution, especially one that involves a view argument in the midst of a path like department/%/list, see the blog post Node ID as View Argument from SEO-friendly URL Path.
In the end this snippet did the job - it just stripped the clean URL and reported back the very last argument.
<?php
$refer= $_SERVER ['REQUEST_URI'];
$nid = explode("/", $refer);
$nid = $nid[3];
?>
Given the comment reply, the above was probably reduced to this, using the Drupal arg() function to get a part of the request path:
<?php
$nid = arg(3);
?>
You should considder the panels module. It is a very big module and requires some work before you really can tap into it's potential. So take that into considderation.
You can use it to setup a page containing several views/blocks that can be placed in different regions. It uses a concept called context which can be anything related to what you are viewing. You can use that context to determine which node is being viewed and not only change blocks but also layout. It is also a bit more clean since you can move the PHP code away from admin interface.
On a side note, it's also written by the views author.
There are a couple of ways to go about this:
You can make your blocks with Views and pass the nid in through an argument.
You can manually pass in the nid by accessing the $view object using the code below. It's an array at $view->result. Each row in the view is an object in that array, and the nid is in that object for each one. So you could run a foreach on that and get all of the nid of all rows in the view pretty easily.
The first option is a lot easier, so if that suits your needs I would go with that.
New about Drupal 7: The correct way to get the node id is using the function menu_get_object();
Example:
$node = menu_get_object();
$contentType = node_type_get_name($node);
Drupal 8 has another method. Check this out:
arg() is deprecated