• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post Request method doesn't work when I use modules

#1
Everything works fine using a module, but there is an issue I get for example I have a login module, there are two methods in the login module controller index method and create method. The index method shows the login form and the create method processes the form. The problem is when I click the submit button on the index method to go to the create method there's an error "controller or method not found", but if I try to access the method directly via GET method I don't get the error. Any suggestions please?

<?php

namespace Modules\Login\Controllers;

class Login extends \CodeIgniter\Controller {

// shows login form
public function index() {
}

public function create () {

if ($_SERVER["REQUEST_METHOD"] === "POST") {
echo "this is a post";
}else{
echo "this is a get";
}

}

}

Any help to why post method returns controller or method error but get shows the echo.
Reply

#2
Take a look at Myth/Auth and you will see how it is done.

Look at the routes in the auth module.

PHP Code:
$routes->group('', ['namespace' => 'Myth\Auth\Controllers'], function($routes) {
    // Login/out
    $routes->get('login''AuthController::login', ['as' => 'login']);
    $routes->post('login''AuthController::attemptLogin');
    
    $routes
->get('logout''AuthController::logout');
}); 

See the top two routes one is a get the other a post.

Now look at the two methods in the AuthController to see how they work.

Myth:Auth
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.