I'm creating a login and logout page on a custom template in yii2. I got an error because of routing.
Please tell how to import Url or manage url.
Add Url class in top of the page.
use yii\helpers\Url;
Refer Url::to()
Related
I'm trying to link the value to particular action, but somehow it doesn't link me to another module.
Here's the value:
'value' = ['module/controller/view', 'id' => $model->id]),
Here is the correct link into which I need to be linked:
localhost/index.php?r=module/controller/view&id=21
Here's the link in which I'm getting linked:
localhost/index.php?r=this-module%module%controller%view&id=21
As you can see somehow I'm staying in the same module and the link doesn't link me to needed module. Could someone explain me why?
You need to add slash:
['/client/entry/view', ...
Without slash it takes it as a subpage of current address.
I am trying to display a specific link on all the pages in my web application. The link is given below
Some text for the link!
My routes file
Route::get('home', 'HomeController#index');
Route::get('path1/path2/path3', 'SomeController#someFunction');
Route::get('my-link', 'SomeController#myLink');
While browsing the web application, when I am at mydoamin.com/home, the link address is mydomain.com/my-link, which is correct.
But when I am at the URL mydoamin.com/path1/path2/path3, the link address becomes mydoamin.com/path1/path2/my-link. Hence, after clicking the link I get 404 error as the path doesn't exist.
How do I make the link to always show mydomain.com/my-link on all the pages without hard-coding the domain name?
Note: I have put the link code Some text for the link! in a partial file; and I am including that file in all the pages.
Why you shouldn't use /my-link?
You could use My link on a site that's running on the root directory (www.domain.com/my-link). But if you're running it in a subdirectory you need to change all the url's.
That's why Laravel introduced named routes, this will automatically creates the correct url.
For example:
If you're site runs at www.domain.com/my-website/ and you need to point to /my-link you need to change all your links in your project to /my-website/....
So I suggest to use named routes.
How to use named routes
Named routes allow the convenient generation of URLs or redirects for specific routes.
And this is de code you need to use:
Route::get('home', ['as' => 'home', 'uses' => 'HomeController#index']);
Route::get('path1/path2/path3', ['as' => 'path3', 'uses' => 'SomeController#someFunction']);
Route::get('my-link', ['as' => 'my-link', 'uses' => 'SomeController#myLink']);
After that you can use:
<a href="{{ url(route('my-link')) }}">
Some text for the link!
</a>
Laravel will automatically create the correct url for the named route you want to use.
Hope this works!
More information at https://laravel.com/docs/5.2/routing#named-routes
Should be href="/my-link", / means start from root.
You may try different ways like ./my-link ,../my-link or ../../my-link to see what happend.
see link: absolute, relative, root
I have used template/login.html for logging in, after successful logged in how to redirect the login.html page to chatwindow.html page (some other html) in Django framework.
So, do I need to redirect it from views.py file or from login.html?
Any help highly appreciated.
Django implements multiple ways to do this:
1. LOGIN_REDIRECT_URL
This is a global setting in your settings.py. It works for all login pages when next= parameter is not specified in login url (e.g. example.com/login?next=/foo).
2. Use next parameter in the login URL
This is usually used to customize the login redirect for individual cases.
The common use-case is when you use #login_required decorator. When a user tries to access a page which requires authentication, a user is then redirected to a login page with a next= parameter pointing to the current page. For example if the user went to /secure/page, then the login page will be something like /login?next=/secure/page. After the user will successfully authenticate, Django will redirect them back to the protected page.
3. Use the hidden input next on the login page
Finally you can set the redirect path in the login form itself:
<form method="POST" ...>
<input typy="hidden" name="next" value="/secure/page">
...
</form>
I would guess that first method might be the most appropriate in your case however keep in mind the other options if you will need them.
I have a MVC4 application and have hosted on IIS8.5 with published file.
I have a link on my cshtml page
<a href='/home/ContactGrabber'>Import Contacts</a>
Here home is controller and ContactGrabber is an action of controller. When I am clicking on this link it show 404 error because url is showing
http://localhost/home/ContactGrabber
It should be
http://localhost/cruuntest/home/ContactGrabber
But when I am running my development code without hosting on IIS. it works fine.
Can anybody help me on this?
Use Url.Action helper for this, so that your url is generated right, by this way you wull face issues:
<a href='#Url.Action("ContactGrabber","home")'>Import Contacts</a>
you can see details of it on MSDN
http://msdn.microsoft.com/en-us/library/dd505232%28v=vs.118%29.aspx
You can also use Html.ActionLink to generate the anchor tag:
Razor:
Html.ActionLink("Import Contacts",
"ContactGrabber", // <-- ActionMethod
"home", // <-- Controller Name.
null, // <-- Route arguments.
null // <-- htmlArguments .. which are none.
)
MSDN docs
Hello, I am working on spring mvc and I have in my home page a a simple link of page register and the register.jsp is contained in my WEB-INF/pages/register.jsp
So on my index.jsp which is in my base folder means in webcontent parllel to WEB-INF so how can i link this register.jsp
<li class="float-block" style="margin-left:50px;"><a href="pages/register.jsp" class="login" title="New User Register here" >Register</a></li>
Please suggest me how to do this to run this link
You can do that by redirecting it to a controller and then to the jsp of your need.
Check this link.
It depends on your configuration. Check request mapping in your controller class and all xml configurations.
Normally it should be something like <a href="/register"> depends on the controller.
a href tag name and request mapping of controller class address should be same and add the object of that class in Form Tag like