Welcome Guest, Not a member yet? Register   Sign In
How to block execution of controller
#1

Hi!
I wanna make a rest api using codeigniter. So i create new core element MY_Controller which extend CI_Controller. I make simple annotation parser but now i have a problem. How i can block execution if http method from annotation doesnt match request http method?
I don't wanna use die(), im not a animal Big Grin
Below an example:
GET user/add

Method in controller/User.php:


PHP Code:
/**
 * @Post
 */
public function add() {
    ....


In that case i don't have method for GET request so i must block that (return error), but how i can do it?

Best regards
NickOver
Reply
#2

(This post was last modified: 06-08-2017, 04:23 PM by skunkbad.)

Check against $_SERVER['REQUEST_METHOD'].


PHP Code:
if( strtolower$_SERVER['REQUEST_METHOD'] ) != 'get' )
      show_404(); 
Reply
#3

My problem isn't get request method or show something to user. I must, in layer between CI_Controller and controller, stop execution controller code. Something like die() but with execution hooks.
Reply
#4

I'll just leave this here: https://codeigniter.com/userguide3/gener...-in-routes
Reply
#5

(06-09-2017, 02:43 AM)NickOver Wrote: My problem isn't get request method or show something to user. I must, in layer between CI_Controller and controller, stop execution controller code. Something like die() but with execution hooks.


PHP Code:
$route['products']['get'] = 'product/list_all';
$route['products/(:any)']['get'] = 'product/show/$1';
$route['products/(:any)']['put'] = 'product/update/$1';
$route['products/(:any)']['delete'] = 'product/delete/$1';
$route['(.+)'] = 'something'

or

https://www.codeigniter.com/user_guide/g...thod-calls
Reply




Theme © iAndrew 2016 - Forum software by © MyBB