File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -805,6 +805,20 @@ public function data($name) {
805
805
return Hash::get ($ this ->data , $ name );
806
806
}
807
807
808
+ /**
809
+ * Safely access the values in $this->params.
810
+ *
811
+ * @param string $name The name of the parameter to get.
812
+ * @return mixed The value of the provided parameter. Will
813
+ * return false if the parameter doesn't exist or is falsey.
814
+ */
815
+ public function param ($ name ) {
816
+ if (!isset ($ this ->params [$ name ])) {
817
+ return false ;
818
+ }
819
+ return $ this ->params [$ name ];
820
+ }
821
+
808
822
/**
809
823
* Read data from `php://input`. Useful when interacting with XML or JSON
810
824
* request body content.
Original file line number Diff line number Diff line change @@ -1768,6 +1768,26 @@ public function testQueryWithArray() {
1768
1768
$ this ->assertNull ($ result );
1769
1769
}
1770
1770
1771
+ /**
1772
+ * Test using param()
1773
+ *
1774
+ * @return void
1775
+ */
1776
+ public function testReadingParams () {
1777
+ $ request = new CakeRequest ();
1778
+ $ request ->addParams (array (
1779
+ 'controller ' => 'posts ' ,
1780
+ 'admin ' => true ,
1781
+ 'truthy ' => 1 ,
1782
+ 'zero ' => '0 ' ,
1783
+ ));
1784
+ $ this ->assertFalse ($ request ->param ('not_set ' ));
1785
+ $ this ->assertTrue ($ request ->param ('admin ' ));
1786
+ $ this ->assertEquals (1 , $ request ->param ('truthy ' ));
1787
+ $ this ->assertEquals ('posts ' , $ request ->param ('controller ' ));
1788
+ $ this ->assertEquals ('0 ' , $ request ->param ('zero ' ));
1789
+ }
1790
+
1771
1791
/**
1772
1792
* test the data() method reading
1773
1793
*
You can’t perform that action at this time.
0 commit comments