I have a big doubt building the structure of my application using Laravel because I want to use two controllers using the same folder, for example, this is my current structure:
Folder structure
app/views/dashboard.blade.php
app/views/settings.blade.php
app/views/business/dashboard.blade.php
app/views/business/settings.blade.php
Routes.php
Route::get('/user/dashboard','HomeController#dashboard');
Route::get('/user/settings','HomeController#settings');
Route::post('/user/login','UserStandardController#login');
Route::post('/user/logout','UserStandardController#logout');
Route::get('/business/dashboard','BusinessController#dashboard');
Route::get('/business/settings','BusinessController#settings');
Route::controller('/','HomeController');
Route::resource('/business','BusinessController');
Route::resource('/','UserStandardController');
Route::resource('/','UserBusinessController');
Basically:
HomeController is used for loading the views for the standard user.
BusinessController is used for loading the views for the business user.
UserStandardController and UserBusinessController are used for the actions for those accounts, for example: login, logout, update settings, update profile, etc.
But the problem is when I try to load mysite.com/user/login, laravel says "Method [login]" doesn't exists and is obviously because in HomeController doesn't exists the login method but exists in UserStandardController... but I don't know how to do this.
I hope you can help me!
You only have POST route for /user/login, you need to have Route::get also.
You have to create a login method in UserStandardController class for this error to go away.
As /user/login is searching for a login method in UserStandardController.
I hope this helps.
Related
I am creating content management system for my project. I have created models and controllers in protected folder for admin-panel. It is working fine in admin panel but for accessing same controllers and models only changing the view for user-panel but I got the error of page not exist. I search that question here but i am satisfied with answer my issue remains the same. Thanks in advance.
double check your route file and see if the link or the page that is missing is added to your route file,
,
your route file depends on what mvc framework you are using,
Use aliases to achieve this, i suppose both the folders are independent applications.
http://www.yiiframework.com/doc-2.0/guide-concept-aliases.html
Create the alias for "admin-panel" in common/config/aliases.php
Yii::setAlias('admin-panel', dirname(dirname(__DIR__)) . '/admin-panel');
and while rendering the page in user-panel give the view path using alias
return $this->render("#admin-panel/views/controllername/file");**
**or whatever your folder structure is
Basically I'm trying to make the admin section of a website harder to find. I have a Controller named built like this
class Admin extends MY_Controller{ // actions below
I like having the name Admin for the controller since it tells any future developer that might work on the site that this controller contains the admin section of the website.
However; as an extra layer of security, I don't want the admin section reachable by simply typing into a browser www.theDomain.com/admin. I would much rather that any route starting with "admin" return my standard 404 response.
I was hoping this could be achieved in the routes file with something like
$route['admin'] = 'error/404';
I would even accept being able to do this in the constructor of my controller. Thoughts anyone?
You can use different Class name for Admin Controller like "Admin48957". In this case, only who knows this Class Name can access the admin section by typing www.theDomain.com/admin48957. (This is the strategy of many modern CMSs. i.e. prestashop)
If you force return it 404. Then you also could not access by yourself.
But if you still want to return 404. You can use show_404() CodeIgniter function.
Perhaps you could call show_404() in your controller method.
Im new to Laravel and just ran into a problem. I got these two routes.
Route::get('posts/{id}', 'PostController#show'); // To show the post
Route::resource('users', 'UserController');
The problem is when i want to go to /posts/create tries to send me to the show function, but ofcourse can find the object. What am i doing wrong? So i thinks the word "create" is an id.
Hope you can help me out.
Right now you do not have RESTful path binded to correct route.
I recommend you to define posts also as resource like this
Route::resource('posts', 'PostController');
Now you have all the RESTful paths automatically created and calling /posts/create will be handled by the create method in controller.
I'm building an admin section and I want to keep urls looking nice but more importantly my code well structured.
I currently have a URL like this
/admin/
which works fine. Another URL like this
/admin/users
which also works fine
However what I now want is an admin page to add a new user which would have the url
/admin/users/add
I cannot seem to get anything to change with that URL, it always triggers the admin/users controllers.
Would appreciate any help
Have you set up a route for this? Controllers by their nature allow you
{Controller Name} / {Controller Action}
To set this up the way you want them you will need to use a route
Route::get('admin/users/add', 'admin#user_add');
This will route all requests to 'admin/users/add' to the admin controller using the method 'get_user_add' or 'action_user_add' depending on whether the controller is restful.
So, I downloaded Tank Auth, and put it in my CodeIgniter libraries folder... Now what? Just a basic implementation of a login page (controller + view) based on this library would be very much appreciated, to get me going in the right direction. Thanks.
Tank auth already have a register page.
Just visit http://yoururl.com/index.php/auth/register
Look at application/controllers/auth.php file.
I recommend setting the 'auth' controller as your default controller in your routes config file. Anytime you visit your root folder and aren't logged in, you'll get the login/register form.
Including the login form should be as simple as including the view in your own view file/ or controller, depending how you like to load views...
$this->load->view('auth/login_form');
or
$this->load->view('auth/register_form');
I wanted to use a header/footer with the standard tank auth views. I copied the 'views/auth' folder and named it 'views/auth_content'. I then went through the views/auth files and added the following:
$this->load->view("tiles/header", $model);;
$this->load->view("auth_content/login_form");
$this->load->view("tiles/footer");
Now 'views/login_form' calls the above code which then embeds the tank auth login_form with your own custom header or footer code. It's non invasive too - just delete the new 'views/auth' folder and rename 'views/auth_content' back to 'views/auth' and you use the original tank auth views again.