I have url like this
http://localhost/belajar4/web/index.php?r=data%2Fsingle&id=2&DataSearch[TANGGAL]=2015-08-04&DataSearch[TANGGAL_SELESAI]=2015-08-12
And I want to get DataSearch['Tanggal'] dan DataSearch[TANGGAL_SELESAI]
I have tried for id with
Yii::$app->request->queryParams['id']
And it was success for it, but not with DataSearch['Tanggal']
When I try for DataSearch['Tanggal'] the error is
Undefined index: DataSearch[TANGGAL]
I think it should have easy to answer but i am newbie for yii2 and i didnt find the solution yet
You can get them from array like this:
Yii::$app->request->queryParams['DataSearch']["TANGGAL_SELESAI"]
Yii::$app->request->queryParams['DataSearch']["TANGGAL"]
You can also use combination of ArrayHelper::getValue() and Yii::$app->request->get() with dot notation:
use Yii;
use yii\helpers\ArrayHelper;
...
$value = ArrayHelper::getValue(Yii::$app->request->get(), 'DataSearch.TANGGAL_SELESAI');
The main advandage is you can avoid Undefined index exception and change default value (third parameter).
Official docs:
Getting values
ArrayHelper::getValue()
Yii::$app->request->get()
I had faced slimier issue & spent lots of time to get the value but somehow I found solution like below.
// Trying to print the value
echo Yii::$app->request->queryParams['DataSearch']['"TANGGAL_SELESAI"'];
echo Yii::$app->request->queryParams['DataSearch']['"TANGGAL"'];
Related
I am currently working on a simple project but I don't wanna use long nasty url's; "cpanel/list?get=types", instead of that I wanna use "cpanel/list?types".
I've tried it by checking if it exists etc. but I couldn't figure it out.
Thanks in advance.
use isset
if(isset($_GET['types'])){
// do soemthing
}else{
// do something else
}
other wise..
$type=$_GET['type'];
Instead of using long query of url you can use sef link(sef url), i suggest you to search this topic.
I'm upgrading a system from CakePHP 1.1 to CakePHP 1.3. In 1.1 I was able to use the HTML helper to do something like:
$html->input('User/email');
To get back data nested in:
$this->data['User']['email']
In the controller. Now I know that $html->input() has been replaced with $this->Form->input(). However, when I try to use:
$this->Form->input('User/email')
I get:
Undefined offset: 2 [CORE\cake\libs\view\helpers\form.php, line 496]
This is coming up because the / in the input. So it seems that 1.3 doesn't like using the / to specify the data should be returned nested. How might I achieve the equivalent of this in 1.3? Thank you much!
In 1.3 you would use
$this->Form->input('User.email');
To set an input for the User model and the email field.
If you have set up your form correctly though, you just need email
For example
$this->Form->create('User');
$this->Form->input('email');
$this->Form->end('Submit');
But in short, to answer your specific question, replace the / with a .
So this currently loads the page for me.
/controllername/view/id/27/title/shoes
However, I want the user to be able to type in:
/controllername/27/shoes
to view the file. So in the routing file, I made a rule like this,
$route['controllername/(:num)/(:any)'] = "controllername/view/id/$1/title/$2";
The original address works with uri_to_assoc(n) because I have it as
$array = $this->uri->uri_to_assoc(3);
$id = $array['id'];
$title = $array['title'];
But once I route it and use the new address to access the file, I get the errors:
Message: Undefined index: id
Message: Undefined index: title
I do not get these errors with my original url way of accessing it. I guess the value of uri_to_assoc(3) changes once the url is changed but I thought the routing function would take care of that. Can anyone help me get rid of these variable errors?
In this case you'll want ruri_to_assoc:
http://codeigniter.com/user_guide/libraries/uri.html
$this->uri->ruri_to_assoc(n)
This function is identical to [uri_to_assoc], except that it creates
an associative array using the re-routed URI in the event you are
using CodeIgniter's URI Routing feature.
You should still validate your array indices anyways, in case the URL itself is invalid.
I'm working with drupal. I have this page something.com/node/13. Inside I have this script
<?php
$door = $_GET["variable"];
echo $door;
?>
When I open the URL like this something.com/node/13?variable=1231 I get the following error:
Error message
Notice: Undefined index: variable in eval() (line 2 of /var/www/html/modules/php/php.module(74) : eval()'d code).
and no output. Any ideas what I might be doing wrong?
The error, partcilarly in drupal 7 simply means that you aren't getting any value for $_GET['variable']. This would be because the url doesn't have a value (someurl?variable=foo). You can avoid the notice by prefixing an # like this:
$door = #$_GET['variable'];
but that won't make the variable return any data. It's pretty unclear from the code you've posted what you're trying to accomplish. You might consider starting there. There is no reason why you can't use $_GET variables in drupal. I do so all the time.
Use drupal_get_query_parameters
Because the rewrite rules with Drupal, you don't grab the $_GET values cleanly directly like that.
I try to use the $_GET[] array in a wordpress template page but I keep getting this error when I use it :
Fatal error: Can't use function return value in write context in ... on line ...
If I comment every call to $_GET, the page displays without error.
How can I use the $_GET array in this case?
Thanks
If you are using empty() incorrectly to check your $_GET[] variables, it can cause that error.
Look at this-> http://blog.ryanrampersad.com/2009/07/20/fatal-error-cant-use-method-return-value-in-write-context/
there is one plugin that can help you http://wordpress.org/extend/plugins/wordpress-registry/