logo
Ask your Symfony questions! Pay money and get answers fast! (more info)

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.

$10
How can I make the model class a variable, with Propel?

Suppose I have code like this:


$c = new Criteria();
$c->add(WssOracleUserCoursePeer::USER_ID, $userid);
$c->add(WssOracleUserCoursePeer::COURSE_ID, $courseId);
$userCourse = WssOracleUserCoursePeer::doSelectOne($c);
if ($userCourse->getStatus() == "C") {
return false;
}


Now I want to change WssOracleUserCoursePeer to a variable that changes depending on circumstance. Simply doing this gives parse errors:


$c = new Criteria();
$c->add($model::USER_ID, $userid);
$c->add($model::COURSE_ID, $courseId);
$userCourse = $model::doSelectOne($c);
if ($userCourse->getStatus() == "C") {
return false;
}


and this also fails:


$c = new Criteria();
$c->add({$model}::USER_ID, $userid);
$c->add({$model}::COURSE_ID, $courseId);
$userCourse = {$model}::doSelectOne($c);
if ($userCourse->getStatus() == "C") {
return false;
}



So how do I do this?

This question has been answered.

Lawrence Krubner | 06/25/10 at 4:28pm Edit


(4) Responses

See a threaded view of answers?

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

  • avatar
    Last edited:
    06/27/10
    1:16pm
    Pascal says:

    Hi, you can try :

     
    $c = new Criteria();

    $c->add(constant($model . '::USER_ID'), $userid);
    $c->add(constant($model . '::COURSE_ID'), $courseId);
    $userCourse = call_user_func(array($model, 'doSelectOne'), $c);
    if ($userCourse->getStatus() == "C") {
    return false;
    }

  • avatar
    Last edited:
    06/25/10
    4:38pm
    Arturo Linares says:

    That is fixed on PHP 5.3.

    Try using the function constant($model.'::USER_ID'); in prior versions.

  • avatar
    Last edited:
    06/25/10
    4:39pm
    Francesco Tassi says:

    it's not really propel related but php related:

    you can get constant value using

    constant($model.'::COURSE_ID');


    and call the doSelectXXX methods using (not sure if both work)

    call_user_func($model.'::doSelectOne', $c);
    call_user_func(array($method, 'doSelectOne'), $c);

    Previous versions of this answer: 06/25/10 at 4:39pm

  • avatar
    Last edited:
    06/25/10
    10:20pm
    GlobalOrangeLab says:

    Try this:


    $oCriteria = new Criteria();

    $oCriteria->add(constant($model . '::USER_ID'), $userid);

    $oCriteria->add(constant($model . '::COURSE_ID'), $courseId);

    $userCourse = call_user_func(array($model, 'doSelectOne'), $oCriteria);

    if ($userCourse->getStatus() == "C") {

    return false;

    }


    Hope this helps you!

This question has expired.





Current status of this question: Completed



Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.