Search code examples
phpwebyiirelationships

Yii 1.1 create relationships automatically


Pago, model exists in Yii. As I create relationships automatically?..

Example:

$pago = new Pago();

Now I want to show information:

echo $pago->iDTIPOTRAMITE->id;

It is assumed that the information must be loaded by default

thanks.


Solution

  • I think I found the solution here: model init()

    With this method, set initial property values.

    Example. Pago model.

    public function init()
    {
        $documentos = DocumentacionT::model()->findAll(array(
          'condition' => 'ID_TIPOSOLICITUD = :idTipo',
          'params' => array(':idTipo' => 5)
        ));
    
        $pagoDocumento = [];
    
        foreach($documentos as $documento)
        {
          $pagoDocumento[] = new PagoDocumento();
        }
    
        $this->pagoDocumentos = $pagoDocumento;
    }