Got 404 on every request when working on two controllers












1















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












share|improve this question

























  • 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
















1















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












share|improve this question

























  • 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














1












1








1








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












share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 you declare 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











  • 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

















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












1 Answer
1






active

oldest

votes


















1














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






share|improve this answer























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


    }
    });














    draft saved

    draft discarded


















    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









    1














    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






    share|improve this answer




























      1














      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






      share|improve this answer


























        1












        1








        1







        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






        share|improve this answer













        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







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 1 at 14:56









        Rana AsadRana Asad

        448




        448
































            draft saved

            draft discarded




















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            Monofisismo

            Angular Downloading a file using contenturl with Basic Authentication

            Olmecas