We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Cannot resolve attribute 'ContCodigo' in the model

I have the following error:

Cannot resolve attribute 'ContCodigo' in the model

In the Next code.

SpmContacto::findFirstByContCodigo()

In the next model

public $CONT_CODIGO;
public $CONT_CEDULA;
public $CONT_RUCIDE;
public $CONT_NOMBRE;
public $CON_ESTADO;
public $CONT_TELEFO;
public $CONT_DIRECC;
public $CONT_AREA;
public $CONT_CARGO;
public $CONT_TIPOXX;
public $CONT_EMAIL;
public $CONT_USUARIO;
public $CONT_CLAVE;
public $CONT_CLAVEE;

public function initialize()
{
    $this->setSchema("SPOLS");
    $this->setSource("'SPM_CONTACTO'");
    $this->hasMany('CONT_CODIGO', 'SpmReferencia', 'CONT_CODIGO', array('alias' => 'SpmReferencia'));
    $this->hasMany('CONT_CODIGO', 'SptDetalle', 'CONT_CODIGO', array('alias' => 'SptDetalle'));
    $this->hasMany('CONT_CODIGO', 'SptEncabezado', 'CONT_CODIGO', array('alias' => 'SptEncabezado'));
}

public static function find($parameters = null)
{
    return parent::find($parameters);
}

public static function findFirst($parameters = null)
{
    return parent::findFirst($parameters);
}
public function getSource()
{
    return 'SPM_CONTACTO';
}
edited Nov '15

Based on the method that is used to determine whether or not (via magic method __call), it looks like underscores are not stripped. Have a gander at the function and try and reverse engineer it :)

https://github.com/phalcon/cphalcon/blob/79a9bfcb8d8eafeb9fe521de42e4e1b50570b10a/phalcon/mvc/model.zep#L3932

Also, considering PHP functions are case-sensitive, you'd probably either want to try

To be honest you shouldnt mix underscore and camelCase notation.



81.2k

I create a table without the underscore, and try again if it works, the function findFirstByCONT_CODIGO not give me any error but returns no data, generare a model and proves coloum map. How definire my own method in the controller?



81.2k

I generate the columnMap unction, but does not return any data but the data if any, also create a table without using underscores but equally not find data

$SPM_CONTACTO = SpmContacto::findFirst("CONT_CODIGO = '0401014717'"); echo "valor ".$SPM_CONTACTO->CONT_CODIGO,"\n";

```public function columnMap()    {
    return array(
        'CONT_CODIGO' => 'CONT_CODIGO',
        'CONT_CEDULA' => 'CONT_CEDULA',
        'CONT_RUCIDE' => 'CONT_RUCIDE',
        'CONT_NOMBRE' => 'CONT_NOMBRE',
        'CON_ESTADO' => 'CON_ESTADO',
        'CONT_TELEFO' => 'CONT_TELEFO',
        'CONT_DIRECC' => 'CONT_DIRECC',
        'CONT_AREA' => 'CONT_AREA',
        'CONT_CARGO' => 'CONT_CARGO',
        'CONT_TIPOXX' => 'CONT_TIPOXX',
        'CONT_EMAIL' => 'CONT_EMAIL',
        'CONT_USUARIO' => 'CONT_USUARIO',
        'CONT_CLAVE' => 'CONT_CLAVE',
        'CONT_CLAVEE' => 'CONT_CLAVEE'
    );
}
```

I mean you shouldnt mix underscore and camelCase in php - you should use one.



81.2k

I just use underscore

Yea but phalcon functions are camelCase and you mix it :P



81.2k

Yes but create another table with camelcase nor returned data is not if something should do but I'm working with Oracle on Linux if you save list, but this command returns data findfirst, I know my syntax error

But you can have table as undersocre and model as camelCase and use columnMap

Yes but create another table with camelcase nor returned data is not if something should do but I'm working with Oracle on Linux if you save list, but this command returns data findfirst, I know my syntax error



81.2k

I create a new model such as this here but the result is the same command using the FindFirst not returna data



    public $USUARIO;
    public $CLAVE;
    public $CLAVEENCRIPTADA;
    public $CODIGO;
    public function initialize()
    {
        $this->setSchema("SPOLS");
        $this->setSource("'USUARIO'");
    }
    public function getSource()
    {
        return 'USUARIO';
    }
    public static function find($parameters = null)
    {
        return parent::find($parameters);
    }
    public static function findFirst($parameters = null)
    {
        return parent::findFirst($parameters);
    }
     public function columnMap()
    {
        return array(
            'USUARIO' => 'USUARIO',
            'CLAVE' => 'CLAVE',
            'CLAVE' => 'CLAVEENCRIPTADA',
            'CODIGO' => 'CODIGO'
        );

But why you using CAPSLOCK ?



81.2k

public function columnMap() { $columns = $this->getModelsMetaData()->getAttributes($this); $map = []; foreach ($columns as $column) $map[$column] = lcfirst(\Phalcon\Text::camelize($column)); return $map; }