yii : Check if isset Yii::app()->request->getParam('uid') - yii

This will return 'not set' if in case of uid will, uid = 0;
if(Yii::app()->request->getParam('uid')){
echo "set";
}else{
echo "not set";
}
How do I check if 'uid' is set?

As far as I can tell, there is no method for checking whether a parameter is set. The source code for getParam() is as follows:
public function getParam($name, $defaultValue=null)
{
return isset($_GET[$name]) ? $_GET[$name] : (isset($_POST[$name]) ? $_POST[$name] : $defaultValue);
}
However, you can implement it yourself:
if (isset($_GET['uid']) || isset($_POST['uid'])){
echo "set";
} else {
echo "not set";
}

Related

createProperty sabre\vobject Uncaught TypeError

I am using the calendar plugin for RoundCube Webmail, any time i am trying to create an event, I receive the following error:
[12-Apr-2022 17:56:08 UTC] PHP Fatal error: Uncaught TypeError: Sabre\VObject\Document::createProperty(): Argument #3 ($parameters) must be of type array, null given, called in /var/www/html/plugins/libcalendaring/libvcalendar.php on line 939 and defined in /usr/share/php/Sabre/VObject/Document.php:103
The functions:
public function createProperty($name, $value = null, array $parameters = null, $valueType = null){
// If there's a . in the name, it means it's prefixed by a groupname.
if (false !== ($i = strpos($name, '.'))) {
$group = substr($name, 0, $i);
$name = strtoupper(substr($name, $i + 1));
} else {
$name = strtoupper($name);
$group = null;
}
$class = null;
if ($valueType) {
// The valueType argument comes first to figure out the correct
// class.
$class = $this->getClassNameForPropertyValue($valueType);
}
if (is_null($class)) {
// If a VALUE parameter is supplied, we should use that.
if (isset($parameters['VALUE'])) {
$class = $this->getClassNameForPropertyValue($parameters['VALUE']);
if (is_null($class)) {
throw new InvalidDataException('Unsupported VALUE parameter for '.$name.' property. You supplied "'.$parameters['VALUE'].'"');
}
} else {
$class = $this->getClassNameForPropertyName($name);
}
}
if (is_null($parameters)) {
$parameters = [];
}
return new $class($this, $name, $value, $parameters, $group);
}
Call it:
$vdt = $cal->createProperty($name, $dt, null, $is_dateonly ? 'DATE' : 'DATE-TIME');
Does anyone know how to fix this?

Prestashop 1.6 l method

There is an issue with the translations, if the translation is missing prestashop is returining empty string, rather than the key.
Does anyone know the location of the 'l' method used in the controllers?
$this->l('string', 'mod'); //This will output '' if string is not translated.
I want to modify the method and make it return the key if the value is empty, but I cant find it.
I'll assume you are referring to an AdminController, since it's the only one using that function. It uses the function:
protected function l($string, $class = null, $addslashes = false, $htmlentities = true)
{
if ($class === null || $class == 'AdminTab') {
$class = substr(get_class($this), 0, -10);
} elseif (strtolower(substr($class, -10)) == 'controller') {
/* classname has changed, from AdminXXX to AdminXXXController, so we remove 10 characters and we keep same keys */
$class = substr($class, 0, -10);
}
return Translate::getAdminTranslation($string, $class, $addslashes, $htmlentities);
}
In your case it would call Translate::getAdminTranslation('string', 'mod', false, true)
In Translate::getAdminTranslation
We have:
...
$string = preg_replace("/\\\*'/", "\'", $string);
$key = md5($string);
if (isset($_LANGADM[$class.$key])) {
$str = $_LANGADM[$class.$key];
} else {
$str = Translate::getGenericAdminTranslation($string, $key, $_LANGADM);
}
...
Since it won't have the $_LANGADM[$class.$key], it will call:
$str = Translate::getGenericAdminTranslation($string, $key, $_LANGADM);
in your case $str = Translate::getGenericAdminTranslation('string', md5('string'), $_LANGADM);
In there we have:
...
if (isset($lang_array['AdminController'.$key])) {
$str = $lang_array['AdminController'.$key];
} elseif (isset($lang_array['Helper'.$key])) {
$str = $lang_array['Helper'.$key];
} elseif (isset($lang_array['AdminTab'.$key])) {
$str = $lang_array['AdminTab'.$key];
} else {
// note in 1.5, some translations has moved from AdminXX to helper/*.tpl
$str = $string;
}
return $str;
So by default if no key is found, the same string that is trying to be translated is returned. So there is no need to change the function.
On the otherhand, make sure the string it's translated to an empty string. You can also debug these functions to make sure your class is correct, and the file that is storing the corresponding translations doesn't have the empty translation for those strings.

Prepare data in controller, not in view (yii)

I made "gearbox"-dropDownList in my Yii webapp, all works perfect, it stores in DB with next values ( 1=> Manual, 2=> Manual-Automat(tiptronick), 3=> Automat), and now i display it in template (view.php) with such not beautiful if-block:
Gearbox:
"
if ($model->gearbox == 1) {
echo 'Manual';
} elseif($model->gearbox == 2) {
echo 'Manual-Automat';
} else {
echo 'Automat';
}
"
Tell me please, should I prepare such data in controller? And if it is possible, can you advice me, please, how it doing.
A other option would be to add this to your model with a virtual attribute, like this:
public function getGearboxName() {
if ($model->gearbox == 1) {
return 'Manual';
} elseif($model->gearbox == 2) {
return 'Manual-Automat';
} else {
return 'Automat';
}
}
This way you can access the value by the gearboxName attribute in your model:
echo $model->gearboxName;
I think in this simple case there is not much to do, but you could prepare it in your controller like this:
Controller:
if ($model->gearbox == 1) {
$gearbox = 'Manual';
} elseif($model->gearbox == 2) {
$gearbox = 'Manual-Automat';
} else {
$gearbox = 'Automat';
}
$this->render('view',array('gearbox'=>$gearbox))
View:
echo $gearbox;

PHP PDO dynamically updating db table with multiple records to a specific user ID

/* Newbie need some help; I am creating a class to auto update my apps db record when instructed to, but I am consistently getting this message below, and for the heck of it, I just not seeing what I am doing wrong. Can someone please look at my codes for me? Thank you.
Warning: PDOStatement::bindParam() expects at least 2 parameters, 1 given in……..on line 331; that where the "else if(is_string($val)){" is located.
*/
// vars given
// DBDriver: MySQL
$myTable = 'seeYou';
$loginDate = NULL;
$ip = $_SERVER['REMOTE_ADDR'];
$date = #date('m/d/Y \a\\t h:i a');
$_id =1;
// data array
$idata = array("last_logged_in"=>$loginDate,
"login_date"=>$date,
"ip_addr"=>$ip
);
class name
{
///------------ other methods here---------///
/**
*--------------------------------------------
* Method - PDO: SET FIELD VALUE PLACEHOLDER
*--------------------------------------------
* #return fields with prefix as placeholder
*/
protected function set_fieldValPlaceHolders(array $data)
{
$set = '';
foreach($data as $field => $value)
{
$set .= $field .'= :'.$field . ',';
}
// remove the last comma
$set = substr($set, 0, -1);
return $set;
}
public function save($data=NULL, $_id = NULL, $rows= NULL, $dbTable= NULL)
{
//----------------- some other codes goes here ----------------//
$id = (int)$_id;
// update row with a specific id
if (isset($id) !== NULL && $rows === NULL)
{
$set = $this->set_fieldValPlaceHolders($data);
$sql = "UPDATE {$dbTable} SET {$set} WHERE user_id = :uid";
try
{
// Build the database statement
$_stmt = $this->_dbConn->prepare($sql);
$_stmt->bindValue(':uid',$id, PDO::PARAM_INT);
foreach ($data as $field => $val)
{
if(is_int($val)){
$_stmt->bindValue(':'.$field.'\', '.$val.', PDO::PARAM_INT');
}
else if(is_string($val)){
$_stmt->bindValue(':'.$field.'\', '.$val.', PDO::PARAM_STR');
}
else if(is_bool($val)){
$_stmt->bindValue(':'.$field.'\', '.$val.', PDO::PARAM_BOOL');
}
else if(is_null($val)){
$_stmt->bindValue(':'.$field.'\', '.$val="null".', PDO::PARAM_NULL');
}
else {
$_stmt->bindValue(':'.$field.'\', '.$val.', NULL');
}
$result = $_stmt->execute();
$num = $_stmt->rowCount();
}
}
catch(PDOException $e)
{
die('Error! The process failed while updating your record. <br /> Line #'.__LINE__ .' '.$e);
}
if ($result === true)
{
return true;
}
}
Check your bindValue calls: You give 1 parameter (a long string). It needs at least two. Check all the '
for example, it should be:
$_stmt->bindValue(':'.$field, $val, PDO::PARAM_INT);

how to fix update error

i want to update all row's alternativegroups with $id value.
the action getting error: coldchain can not be null.
when i search the db for pk = $a, It's coldchain value is boolen(false). and db is postgresql
how can i set $q->attributes without posting other values?
public function actionUpdate($id){
if (isset($_POST['forms'])){
$arr = explode(',', $_POST['forms']);
foreach ($arr as $a){
$q = MedicineDrugform::model()->findbypk($a);
$q->alternativegroup = $id;
if ($q->save()){
echo $q->id."q saved <br />";
}
else {
echo "<pre>";
print_r($q->getErrors());
}
die();
$qu = MedicineDrugformUpdate::model()->findbyattributes(array('drug_form_id'=>$a));
$quu = MedicineDrugformUpdate::model()->findbypk($qu->id);
$quu->alternativegroup = $id;
if ($quu->save()){
echo $quu->id."qu saved <br />";
}
}
die();
$this->render('/site/messages', array('message'=>'formsaved'));
}
$this->render('add', array('id'=>$id));
}
maybe it cant find the corresponding record for
$q = MedicineDrugform::model()->findbypk($a);