Got 404 on every request when working on two controllers
I am developing a back end system using slim-3.In app i have multiple controllers like if for Books and Users there are two different controllers in which all calls of each is placed.So when i declare controllers in index.php file then only one controller request is accept other controller request return 404 page not found.When i remove declaration of one controller then other worked.
e.g i have two controllers like User Controller and Provider Controller when i declare both of them in index.php then only Provider Controller is worked.But when i remove declaration of Provider Controller then User controllers api calls is working well but when i add the Provider Controller then User Controller api calls return 404.
here is index.php code
<?php
use PsrHttpMessageServerRequestInterface as Request;
use PsrHttpMessageResponseInterface as Response;
require '../vendor/autoload.php';
$app = new SlimApp;
$app->get('/hello/{name}', function (Request $request, Response $response,
array $args) {
$name = $args['name'];
$response->getBody()->write("Hello, $name");
return $response;
});
require '../src/controllers/UserController.php';
require '../src/controllers/ProviderController.php';
require '../src/models/GeneralResponse.php';
require '../src/database/UserOperations.php';
require '../src/database/ProviderOperations.php';
require '../src/models/User.php';
require '../src/models/Provider.php';
require '../src/utils/Utils.php';
$app->run();
here is provider controller
<?php
use PsrHttpMessageServerRequestInterface as Request;
use PsrHttpMessageResponseInterface as Response;
require '../vendor/autoload.php';
$app = new SlimApp;
$app->post('/provider/register',function($request,$response,$args){
try{
$appresponse=new GeneralResponse();
$formDataArry = $request->getParsedBody();
$email=$formDataArry['email'];
$passwordRaw=$formDataArry['password'];
$firstname=$formDataArry['firstname'];
});
here is User controller
<?php
require '../vendor/autoload.php';
use PsrHttpMessageServerRequestInterface as Request;
use PsrHttpMessageResponseInterface as Response;
$app = new SlimApp;
//Registration of user end point
$app->post('/user/register',function($request,$response,$args){
try{
$appresponse=new GeneralResponse();
$formDataArry = $request->getParsedBody();
$email=$formDataArry['email'];
$passwordRaw=$formDataArry['password'];
});
php slim slim-3
|
show 1 more comment
I am developing a back end system using slim-3.In app i have multiple controllers like if for Books and Users there are two different controllers in which all calls of each is placed.So when i declare controllers in index.php file then only one controller request is accept other controller request return 404 page not found.When i remove declaration of one controller then other worked.
e.g i have two controllers like User Controller and Provider Controller when i declare both of them in index.php then only Provider Controller is worked.But when i remove declaration of Provider Controller then User controllers api calls is working well but when i add the Provider Controller then User Controller api calls return 404.
here is index.php code
<?php
use PsrHttpMessageServerRequestInterface as Request;
use PsrHttpMessageResponseInterface as Response;
require '../vendor/autoload.php';
$app = new SlimApp;
$app->get('/hello/{name}', function (Request $request, Response $response,
array $args) {
$name = $args['name'];
$response->getBody()->write("Hello, $name");
return $response;
});
require '../src/controllers/UserController.php';
require '../src/controllers/ProviderController.php';
require '../src/models/GeneralResponse.php';
require '../src/database/UserOperations.php';
require '../src/database/ProviderOperations.php';
require '../src/models/User.php';
require '../src/models/Provider.php';
require '../src/utils/Utils.php';
$app->run();
here is provider controller
<?php
use PsrHttpMessageServerRequestInterface as Request;
use PsrHttpMessageResponseInterface as Response;
require '../vendor/autoload.php';
$app = new SlimApp;
$app->post('/provider/register',function($request,$response,$args){
try{
$appresponse=new GeneralResponse();
$formDataArry = $request->getParsedBody();
$email=$formDataArry['email'];
$passwordRaw=$formDataArry['password'];
$firstname=$formDataArry['firstname'];
});
here is User controller
<?php
require '../vendor/autoload.php';
use PsrHttpMessageServerRequestInterface as Request;
use PsrHttpMessageResponseInterface as Response;
$app = new SlimApp;
//Registration of user end point
$app->post('/user/register',function($request,$response,$args){
try{
$appresponse=new GeneralResponse();
$formDataArry = $request->getParsedBody();
$email=$formDataArry['email'];
$passwordRaw=$formDataArry['password'];
});
php slim slim-3
Your sample code only includes one route definition which has nothing to do with your controllers. Please update your code and add the routes that you said are returning a 404 error.
– Nima
Jan 1 at 14:24
This is index.php file other routes are in User Controller file and Provider Controller
– Rana Asad
Jan 1 at 14:26
So please let us know about them.
– Nima
Jan 1 at 14:27
When i decalre both controller User and Provider then only Provider Controller routes are working and User controller routes return 404 but when i remove Provider then User Controller routes are working.
– Rana Asad
Jan 1 at 14:28
Your code does not show how youdeclare
these controllers and routes. We need to see them to be able to help.
– Nima
Jan 1 at 14:31
|
show 1 more comment
I am developing a back end system using slim-3.In app i have multiple controllers like if for Books and Users there are two different controllers in which all calls of each is placed.So when i declare controllers in index.php file then only one controller request is accept other controller request return 404 page not found.When i remove declaration of one controller then other worked.
e.g i have two controllers like User Controller and Provider Controller when i declare both of them in index.php then only Provider Controller is worked.But when i remove declaration of Provider Controller then User controllers api calls is working well but when i add the Provider Controller then User Controller api calls return 404.
here is index.php code
<?php
use PsrHttpMessageServerRequestInterface as Request;
use PsrHttpMessageResponseInterface as Response;
require '../vendor/autoload.php';
$app = new SlimApp;
$app->get('/hello/{name}', function (Request $request, Response $response,
array $args) {
$name = $args['name'];
$response->getBody()->write("Hello, $name");
return $response;
});
require '../src/controllers/UserController.php';
require '../src/controllers/ProviderController.php';
require '../src/models/GeneralResponse.php';
require '../src/database/UserOperations.php';
require '../src/database/ProviderOperations.php';
require '../src/models/User.php';
require '../src/models/Provider.php';
require '../src/utils/Utils.php';
$app->run();
here is provider controller
<?php
use PsrHttpMessageServerRequestInterface as Request;
use PsrHttpMessageResponseInterface as Response;
require '../vendor/autoload.php';
$app = new SlimApp;
$app->post('/provider/register',function($request,$response,$args){
try{
$appresponse=new GeneralResponse();
$formDataArry = $request->getParsedBody();
$email=$formDataArry['email'];
$passwordRaw=$formDataArry['password'];
$firstname=$formDataArry['firstname'];
});
here is User controller
<?php
require '../vendor/autoload.php';
use PsrHttpMessageServerRequestInterface as Request;
use PsrHttpMessageResponseInterface as Response;
$app = new SlimApp;
//Registration of user end point
$app->post('/user/register',function($request,$response,$args){
try{
$appresponse=new GeneralResponse();
$formDataArry = $request->getParsedBody();
$email=$formDataArry['email'];
$passwordRaw=$formDataArry['password'];
});
php slim slim-3
I am developing a back end system using slim-3.In app i have multiple controllers like if for Books and Users there are two different controllers in which all calls of each is placed.So when i declare controllers in index.php file then only one controller request is accept other controller request return 404 page not found.When i remove declaration of one controller then other worked.
e.g i have two controllers like User Controller and Provider Controller when i declare both of them in index.php then only Provider Controller is worked.But when i remove declaration of Provider Controller then User controllers api calls is working well but when i add the Provider Controller then User Controller api calls return 404.
here is index.php code
<?php
use PsrHttpMessageServerRequestInterface as Request;
use PsrHttpMessageResponseInterface as Response;
require '../vendor/autoload.php';
$app = new SlimApp;
$app->get('/hello/{name}', function (Request $request, Response $response,
array $args) {
$name = $args['name'];
$response->getBody()->write("Hello, $name");
return $response;
});
require '../src/controllers/UserController.php';
require '../src/controllers/ProviderController.php';
require '../src/models/GeneralResponse.php';
require '../src/database/UserOperations.php';
require '../src/database/ProviderOperations.php';
require '../src/models/User.php';
require '../src/models/Provider.php';
require '../src/utils/Utils.php';
$app->run();
here is provider controller
<?php
use PsrHttpMessageServerRequestInterface as Request;
use PsrHttpMessageResponseInterface as Response;
require '../vendor/autoload.php';
$app = new SlimApp;
$app->post('/provider/register',function($request,$response,$args){
try{
$appresponse=new GeneralResponse();
$formDataArry = $request->getParsedBody();
$email=$formDataArry['email'];
$passwordRaw=$formDataArry['password'];
$firstname=$formDataArry['firstname'];
});
here is User controller
<?php
require '../vendor/autoload.php';
use PsrHttpMessageServerRequestInterface as Request;
use PsrHttpMessageResponseInterface as Response;
$app = new SlimApp;
//Registration of user end point
$app->post('/user/register',function($request,$response,$args){
try{
$appresponse=new GeneralResponse();
$formDataArry = $request->getParsedBody();
$email=$formDataArry['email'];
$passwordRaw=$formDataArry['password'];
});
<?php
use PsrHttpMessageServerRequestInterface as Request;
use PsrHttpMessageResponseInterface as Response;
require '../vendor/autoload.php';
$app = new SlimApp;
$app->post('/provider/register',function($request,$response,$args){
try{
$appresponse=new GeneralResponse();
$formDataArry = $request->getParsedBody();
$email=$formDataArry['email'];
$passwordRaw=$formDataArry['password'];
$firstname=$formDataArry['firstname'];
});
<?php
use PsrHttpMessageServerRequestInterface as Request;
use PsrHttpMessageResponseInterface as Response;
require '../vendor/autoload.php';
$app = new SlimApp;
$app->post('/provider/register',function($request,$response,$args){
try{
$appresponse=new GeneralResponse();
$formDataArry = $request->getParsedBody();
$email=$formDataArry['email'];
$passwordRaw=$formDataArry['password'];
$firstname=$formDataArry['firstname'];
});
<?php
require '../vendor/autoload.php';
use PsrHttpMessageServerRequestInterface as Request;
use PsrHttpMessageResponseInterface as Response;
$app = new SlimApp;
//Registration of user end point
$app->post('/user/register',function($request,$response,$args){
try{
$appresponse=new GeneralResponse();
$formDataArry = $request->getParsedBody();
$email=$formDataArry['email'];
$passwordRaw=$formDataArry['password'];
});
<?php
require '../vendor/autoload.php';
use PsrHttpMessageServerRequestInterface as Request;
use PsrHttpMessageResponseInterface as Response;
$app = new SlimApp;
//Registration of user end point
$app->post('/user/register',function($request,$response,$args){
try{
$appresponse=new GeneralResponse();
$formDataArry = $request->getParsedBody();
$email=$formDataArry['email'];
$passwordRaw=$formDataArry['password'];
});
php slim slim-3
php slim slim-3
edited Jan 1 at 14:56
anotherfred
625815
625815
asked Jan 1 at 13:58
Rana AsadRana Asad
448
448
Your sample code only includes one route definition which has nothing to do with your controllers. Please update your code and add the routes that you said are returning a 404 error.
– Nima
Jan 1 at 14:24
This is index.php file other routes are in User Controller file and Provider Controller
– Rana Asad
Jan 1 at 14:26
So please let us know about them.
– Nima
Jan 1 at 14:27
When i decalre both controller User and Provider then only Provider Controller routes are working and User controller routes return 404 but when i remove Provider then User Controller routes are working.
– Rana Asad
Jan 1 at 14:28
Your code does not show how youdeclare
these controllers and routes. We need to see them to be able to help.
– Nima
Jan 1 at 14:31
|
show 1 more comment
Your sample code only includes one route definition which has nothing to do with your controllers. Please update your code and add the routes that you said are returning a 404 error.
– Nima
Jan 1 at 14:24
This is index.php file other routes are in User Controller file and Provider Controller
– Rana Asad
Jan 1 at 14:26
So please let us know about them.
– Nima
Jan 1 at 14:27
When i decalre both controller User and Provider then only Provider Controller routes are working and User controller routes return 404 but when i remove Provider then User Controller routes are working.
– Rana Asad
Jan 1 at 14:28
Your code does not show how youdeclare
these controllers and routes. We need to see them to be able to help.
– Nima
Jan 1 at 14:31
Your sample code only includes one route definition which has nothing to do with your controllers. Please update your code and add the routes that you said are returning a 404 error.
– Nima
Jan 1 at 14:24
Your sample code only includes one route definition which has nothing to do with your controllers. Please update your code and add the routes that you said are returning a 404 error.
– Nima
Jan 1 at 14:24
This is index.php file other routes are in User Controller file and Provider Controller
– Rana Asad
Jan 1 at 14:26
This is index.php file other routes are in User Controller file and Provider Controller
– Rana Asad
Jan 1 at 14:26
So please let us know about them.
– Nima
Jan 1 at 14:27
So please let us know about them.
– Nima
Jan 1 at 14:27
When i decalre both controller User and Provider then only Provider Controller routes are working and User controller routes return 404 but when i remove Provider then User Controller routes are working.
– Rana Asad
Jan 1 at 14:28
When i decalre both controller User and Provider then only Provider Controller routes are working and User controller routes return 404 but when i remove Provider then User Controller routes are working.
– Rana Asad
Jan 1 at 14:28
Your code does not show how you
declare
these controllers and routes. We need to see them to be able to help.– Nima
Jan 1 at 14:31
Your code does not show how you
declare
these controllers and routes. We need to see them to be able to help.– Nima
Jan 1 at 14:31
|
show 1 more comment
1 Answer
1
active
oldest
votes
Basically i created separate instance of SlimApp in every controller these instance overwrite the instance of index file therefore it ignored the require of every controller simply remove $app = new SlimApp; from controllers file but index.php.Problem will fixed by this.
For more information visit this
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53996058%2fgot-404-on-every-request-when-working-on-two-controllers%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Basically i created separate instance of SlimApp in every controller these instance overwrite the instance of index file therefore it ignored the require of every controller simply remove $app = new SlimApp; from controllers file but index.php.Problem will fixed by this.
For more information visit this
add a comment |
Basically i created separate instance of SlimApp in every controller these instance overwrite the instance of index file therefore it ignored the require of every controller simply remove $app = new SlimApp; from controllers file but index.php.Problem will fixed by this.
For more information visit this
add a comment |
Basically i created separate instance of SlimApp in every controller these instance overwrite the instance of index file therefore it ignored the require of every controller simply remove $app = new SlimApp; from controllers file but index.php.Problem will fixed by this.
For more information visit this
Basically i created separate instance of SlimApp in every controller these instance overwrite the instance of index file therefore it ignored the require of every controller simply remove $app = new SlimApp; from controllers file but index.php.Problem will fixed by this.
For more information visit this
answered Jan 1 at 14:56
Rana AsadRana Asad
448
448
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53996058%2fgot-404-on-every-request-when-working-on-two-controllers%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Your sample code only includes one route definition which has nothing to do with your controllers. Please update your code and add the routes that you said are returning a 404 error.
– Nima
Jan 1 at 14:24
This is index.php file other routes are in User Controller file and Provider Controller
– Rana Asad
Jan 1 at 14:26
So please let us know about them.
– Nima
Jan 1 at 14:27
When i decalre both controller User and Provider then only Provider Controller routes are working and User controller routes return 404 but when i remove Provider then User Controller routes are working.
– Rana Asad
Jan 1 at 14:28
Your code does not show how you
declare
these controllers and routes. We need to see them to be able to help.– Nima
Jan 1 at 14:31