php-mvc
php-mvc copied to clipboard
I have an Issue with multiple Apps
Hi i tried you project without twig and composer.
I have few issues that i need to check the user logged in or not first, and there are seperate apps i am working now on same webapp, it means App 1: localhost/myapp1/ App 2: localhost/myapp2/
i am totally confused how to router them properly and user login wont do with the mysql db it done with another api
can you please suggest me how to route to them default to my login page in the root folder i am not using the public folder anyway, and how to route to my multiple apps
i have done some working with procedural php but i want to do it in MVC. Please help me on this.
Create an additional .htaccess file in each application, i.e. myapp1/.htaccess that contains the following:
RewriteEngine On
RewriteCond %{REQUEST_URI} !public/
RewriteRule (.*) public/$1 [L]
This will rewrite the URL to remove "public".
Then, in the .htaccess file inside the application, add a RewriteBase line that contains the folder name, so myapp1/public/.htaccess would look like this:
RewriteEngine On
RewriteBase /myapp1
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ index.php?$1 [L,QSA]
This will let you have more than one project, and the URLs will be localhost/myapp1/posts/index and so on. You'll have to take the subfolder into account with links and redirects inside the application.
Sorry I forgot to mention I use nginx and I am not using public folder, directly using index file from root folder I just want the routes that work with namespace got from url example.
http://mydomain/app1/Home/Index i need the routing that app1 is namespace, Home is Controller and Index is action in that same app there can be a another url like below
http://mydomain/app2/Home/Index i need the routing that app2 is namespace, Home is Controller and Index is action
can you please help me on index.php and routes.php so it should take namespace, controller and action and i need when the website loaded it should go for app1/Home/Index here i will check the session and redirect to login and after logging i will render the app1/Home/Index
i am totally confused how i can do this
I haven't tried it on nginx, but you can add a route that includes a fixed part that includes a namespace in the parameters, e.g.
$router->add('app1/{controller}/{action}',["namespace"=>"app1"]);
Is that what you meant?
can you please tell me one thing without adding the route it wont work ?
I'm afraid I don't understand what you mean, please can you give me more details?
Hello, I am trying to put the route into operation on a web server, but when I send the user and the password, the following appears in the route:
%7B%7B%20route%20%7D%7D/login/index
I don't know if it is related to the .htaccess since the application is not found in the root directory.
Thanks for your help.
Decoded, that's this code:
{{ route }}/login/index
it looks like Twig isn't installed, so the web server isn't interpreting the Twig code. Did you copy the vendor folder to the live web server?
Decoded, that's this code:
{{ route }}/login/indexit looks like Twig isn't installed, so the web server isn't interpreting the Twig code. Did you copy the vendor folder to the live web server?
Thanks, in this line I had the error
public function requireLogin()
{
if (! Auth::getUser()) {
Flash::addMessage('Por favor iniciar sesión en esta página', Flash::INFO);
Auth::rememberRequestedPage();
$this->redirect(dirname($_SERVER['PHP_SELF']) .'/login/index');
}
}