hemc4
hemc4

Reputation: 1633

Get Request Is Considered As Post

I have strange problem. I created a link:

<a href="/module/default/editEvent" style="font-size: 14px;">Edit Event</a>

and an action

public function actionEditEvent(){
      if(isset($_POST)){
          echo '<pre>';
          print_r($_POST);
          die;
      }
     $this->render('editEvent');
    }

when I click on link it prints blank array.

Can anyone tell me reason for that?<

Upvotes: 0

Views: 70

Answers (5)

MrSoundless
MrSoundless

Reputation: 1384

Actually, since you're using yii, you can use:

if (Yii::app()->request->isPostRequest) {
    // Post request
}

Upvotes: 0

Dr. Dan
Dr. Dan

Reputation: 2288

$_POST is a superglobal array, so it will always be set regardless whether it has any value or not. Use empty() instead. You can also use $_SERVER['REQUEST_METHOD'] as suggested by Alexander Taver

Upvotes: 2

Sivagopal Manpragada
Sivagopal Manpragada

Reputation: 1634

$_POST is a PHP global array it is avilable every where in php

you chancheck like these if(count($_POST)>0)

if($_SERVER['REQUEST_METHOD']=="POST") 

Upvotes: 0

Alexander Taver
Alexander Taver

Reputation: 474

Check $_SERVER['REQUEST_METHOD'] to find out whether it was GET or POST request

Upvotes: 1

Manish Goyal
Manish Goyal

Reputation: 700

As Dan Said $_POST is super global array , hence it will always be set

Instead you should use

!empty($_POST)

Thanks

Upvotes: 1

Related Questions