Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

[plugin yii] Trouver le title en passant par Question::model ?

  • fredericL
  • fredericL's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 5 months ago #205489 by fredericL
Bonjour à tous,

Je développe un petit plugin Yii et j'aimerai savoir quelle est le "title" de la question qui lui a été posée.
En fonction du title, tel ou tel code sera exécuté.

Connaissant le "qId", j'ai réussi à obtenir mon "title", mais je suis passé par une interrogation SQL sur la base de donnée. Voici mon code.
Code:
$qid=Yii::app()->request->getParam('qid');
$oQuestion = Yii::app()->db->createCommand();
$title = $oQuestion
                    ->select('title')
                    ->from('lime_questions')
                    ->where('qid=:qid', array(':qid'=>$qid))
                    ->queryScalar();

Mais je ne suis pas très satisfait d'avoir à requêter en SQL. N'y aurait il pas moyen d'utiliser Question::model()-find() pour arriver au même résultat ?
Code:
$x = Question::model()->find('qid=:qid',array(':qid'=>$qid));

A partir de là, comment faire pour arriver à l'attribut désiré ?

Merci mille fois :-)
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 5 months ago #205491 by Joffm
This is the English part of the forum.
Please write English or use the French part.

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The following user(s) said Thank You: DenisChenu
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 5 months ago #205531 by DenisChenu
www.yiiframework.com/doc/api/1.1/CActiveRecord
Code:
$oQuestion = \Question::model()->findByPk(array('qid'=>$qid,'language'=>$language));
if($oQuestion) {
    $title = $oQuestion->title;
}

Else : here : you seem to use 3.X, we update DB for question in 4.X.

You can use find too for exemple.

Question model are documented in code (maybe with some error) : github.com/LimeSurvey/LimeSurvey/blob/cf...els/Question.php#L20 (here for 3.X)

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose