Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I have an Issue with multiple Apps #60

Open
kmkmahesh opened this issue Jun 8, 2020 · 8 comments
Open

I have an Issue with multiple Apps #60

kmkmahesh opened this issue Jun 8, 2020 · 8 comments

Comments

@kmkmahesh
Copy link

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.

@daveh
Copy link
Owner

daveh commented Jun 9, 2020

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.

@kmkmahesh
Copy link
Author

kmkmahesh commented Jun 9, 2020

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

@daveh
Copy link
Owner

daveh commented Jun 9, 2020

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?

@kmkmahesh
Copy link
Author

can you please tell me one thing without adding the route it wont work ?

@daveh
Copy link
Owner

daveh commented Jun 10, 2020

I'm afraid I don't understand what you mean, please can you give me more details?

@feramos60
Copy link

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.

@daveh
Copy link
Owner

daveh commented Feb 20, 2022

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?

@feramos60
Copy link

feramos60 commented Feb 20, 2022

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?

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');
        }
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants