Giter VIP home page Giter VIP logo

Comments (10)

parkerj avatar parkerj commented on May 19, 2024

Try this:

$router->post('/', function () {
    error_log(var_export($_POST, true));
});

The above code will post $_POST variables to your system's error log, so you can see if it is working or not.

from router.

derBoehm avatar derBoehm commented on May 19, 2024

echo print_r($_POST);

from router.

bramus avatar bramus commented on May 19, 2024

Please make sure that you're meeting the necessary prerequisites. Since you can't see anything in $_REQUEST (and thus $_POST), I suspect you haven't set up URL Rewriting properly.

Also make sure you're starting your router with $router->run();, otherwise nothing will happen.

from router.

abmmhasan avatar abmmhasan commented on May 19, 2024
$router = new Router;
    $router->set404(function () {
        header($_SERVER['SERVER_PROTOCOL'] . ' 404 Not Found');
        echo '404, route not found!';
    });

    // Before Router Middleware
    $router->before('GET', '/.*', function () {
		header('Content-type: application/json');
    });
    // Subrouting
    $router->mount('/mff', function () use ($router) {
        $router->get('/', function () {
			echo "Get Request";
        });
        $router->post('/', function () {
            $messages = array();
            if(isset($_REQUEST))$chk='POST Set';
           else $chk='POST not Set'; //checked with $_post also but not working!!!
			array_push($messages,
			array(
			'speech'=>'TEST FLY'.$chk,
			'type'=>0
			));
            echo json_encode(array("messages"=>$messages), JSON_UNESCAPED_UNICODE);
        });
    });

$router->run();

Is what I'm using! Please let me know whats the problem there!

from router.

ovflowd avatar ovflowd commented on May 19, 2024

Why are you doing this:

$router->set404(function () {
        header($_SERVER['SERVER_PROTOCOL'] . ' 404 Not Found');
        echo '404, route not found!';
    });

Just for asking.

Also is $_REQUEST, not $_request. It's case sensitive.

A proper way would be using something like:

file_get_contents("php://input");

Instead of $_REQUEST.

Read more: https://stackoverflow.com/questions/8893574/php-php-input-vs-post

from router.

ovflowd avatar ovflowd commented on May 19, 2024

I would truly recommend you learn a little bit more of php, by reading their documentation.

But anyways, we're here to help you 😄

from router.

abmmhasan avatar abmmhasan commented on May 19, 2024

I know about the case sensitive fact! I was manually writing it in some places! that is why case got in way!

from router.

ovflowd avatar ovflowd commented on May 19, 2024

Oh I see, sorry for my misunderstood. But anyways, give a check in the php://input

The $_POST and $_REQUEST have nothing to do with the router itself.

from router.

abmmhasan avatar abmmhasan commented on May 19, 2024

thanks but the script itself now started to work! I think it was not about my code but the sync problem earlier. The code was not updating on server.

from router.

ovflowd avatar ovflowd commented on May 19, 2024

So you solved your problem? That's amazing! You can close this issue if you want :)

from router.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.