Problema Combobox popular textfield

Pessoal consegui fazer funcionar o form já chama o controller.

Meu problema agora é o seguinte:

Não estou sabendo como se busca um campo no banco (número maximo final) e jogar no textfield estou tentando assim:

$parametro =((int)$_POST[‘id_tp_num_sequencial’]);

  //dd($parametro);





  $posts = NumSequencial::model()->findBySql("SELECT MAX(ns.num_sequencial_final) FROM sch_scspm.tb_num_sequencial ns, sch_scspm.tb_tp_num_sequencial tpns


    WHERE ns.id_tp_num_sequencial = tpns.id_tp_num_sequencial


                            AND


                            ns.id_tp_num_sequencial = :keyword", array(':keyword'=>$parametro)); 


  


  





     


        echo CHtml::tag('input', array( 'type'=>'text' , 'value' => $posts));

O parâmetro já está vindo corretamente, o sql também está correto (executando diretamente no banco de dados), porém não consigo "jogar" o campo buscado para o textfield.

Já tentei vários métodos find e ambos retornam um objeto com 12 e não o campo que necessito. Como faço para trazer ele?

Se eu alterar o value para qualquer valor ele preenche o textfield Alguém poderia me dar uma luz?

Obrigado!

samjs,

O $posts está retornando o que?

Coloca uma alias no MAX() para pode resgatar no input.


MAX(ns.num_sequencial_final) as maximo

E para jogar no input usa o CHtml::textField().


echo CHtml::textField('valor_maximo', $posts->maximo);

A consulta feita, vai retornar o seu modelo, "NumSequencial".

A variável $posts, deve ser o seu modelo, portanto, para exibir o seu valor no input, tente o seguinte…


echo CHtml::tag('input', array( 'type'=>'text' , 'value' => $posts->num_sequencial_final));

Não julgo como sendo a melhor forma de se fazer, pois gosto de utilizar o CActiveForm, mas deve funcionar.

Newerton retorna

$posts object NumSequencial {12}

tentei das duas formas que vocês falaram e simplesmente o campo textfield não recebe nenhum valor.

O método findBySql, será que ta certo da forma que eu fiz em relação a sintaxe?

Dei dd, um var_dump depois da consulta para verificar o conteúdo e o yii ignora e o comando não executado

$parametro =((int)$_POST[‘id_tp_num_sequencial’]);

 //dd($parametro);


 $posts = NumSequencial::model()->findBySql("SELECT MAX(ns.num_sequencial_final) as maximo FROM sch_scspm.tb_num_sequencial ns, sch_scspm.tb_tp_num_sequencial tpns


WHERE ns.id_tp_num_sequencial = tpns.id_tp_num_sequencial


AND


ns.id_tp_num_sequencial = :keyword", array(':keyword'=>$parametro));  

var_dump($posts->maximo);

 echo CHtml::textField('valor_maximo', $posts->maximo);


  


   // echo CHtml::tag('input', array( 'type'=>'text' , 'value' => $posts->maximo))

samjf, desculpa cara!

Eu li errado, achei que você estava fazendo findByPk, com a consulta lá nem fazia sentido você estar usando o findByPk, por isso estranhei.

Tenta o seguinte…


$connection=Yii::app()->db;

	    

var_dump($connection->createCommand("<sua_consulta>")->queryRow());

#Edit

Se preferir usa "queryScalar" ao invés de "queryRow".

Lothor

$connection->createCommand(…)->queryRow() array (1)

esse e o resultado do dump, fiz através do comando dd pois o var_dump não funcionou.

o que isso quer dizer?

samjf,

Você tentou fazer o que o Newerton falou na primeira resposta?

Eu acabei de testar aqui e funcionou perfeitamente, a única coisa que tive que fazer foi adicionar uma propriedade maximo no model.

qualquer coisa, posta aí.

abraço…

Tentei sim, não aparece nada no textfield debaixo, que loucura.

NumSequencialController:


   public function actionUdpateTxt() {

      

        $parametro =((int)$_POST['id_tp_num_sequencial']);

        //dd($parametro);


        $posts = NumSequencial::model()->findBySql("SELECT MAX(ns.num_sequencial_final) as maximo FROM sch_scspm.tb_num_sequencial ns, sch_scspm.tb_tp_num_sequencial tpns

        WHERE ns.id_tp_num_sequencial = tpns.id_tp_num_sequencial

         AND

            ns.id_tp_num_sequencial = :keyword", array(':keyword'=>$parametro));  

    

        echo CHtml::textField('valor_maximo', $posts->maximo);

   

    }

_form.php


<div class="row">


        

                 <?php echo CHtml::activeLabelEx($model,'id_tp_num_sequencial'); ?>


                 <?php

                                               array('empty'=>'Escolha um Tipo de Receita', 'submit'=>array('numSequencial/buscaultimo', 'id'=>$model->id_tp_num_sequencial)));

            ?>

             <?php echo $form->error($model,'id_tp_num_sequencial'); ?>

      	</div>

	<div class="row">

		<?php echo $form->labelEx($model,'num_sequencial_inicial'); ?>

		<?php echo $form->textField($model,'num_sequencial_inicial'); ?>

		<?php echo $form->error($model,'num_sequencial_inicial'); ?>

	</div>




   <?php

            $options = array(

               'empty'=>'Escolha um Tipo de Receita',

                'id' => 'id_tp_num_sequencial',

                'ajax' => array('type'=>'POST'

                                , 'url'=>CController::createUrl('NumSequencial/UdpateTxt')

                                , 'update'=>'#param_id'  //selector to update

                )

            );


        echo CHtml::dropDownList('id_tp_num_sequencial', '', CHtml::listData(TpNumSequencial::model()->findAll(), 'id_tp_num_sequencial', 'tp_num_sequencial'), $options);

    ?>


    <div id="param_id" class="row">

        <?php

            echo CHtml::textField( 'temp_id') ;

        ?>

    </div>

No model adicionei essa linha:


 * @property integer $maximo

Tentei de várias formas e não consegui, quando uso findAll aparece mas não é o que necessito necessito buscar o numero final máximo na tabela dessa forma não deu:




  $sql='SELECT MAX(ns.num_sequencial_final) as maximo FROM sch_scspm.tb_num_sequencial ns, sch_scspm.tb_tp_num_sequencial tpns

        WHERE ns.id_tp_num_sequencial = tpns.id_tp_num_sequencial

         AND

            ns.id_tp_num_sequencial = :keyword'; 

       $data=NumSequencial::model()->findBySql($sql, 

                    array(':keyword'=>(int) $_POST['id_tp_num_sequencial']));

       

        $data=CHtml::listData($data,'id_num_sequencial','num_sequencial_final');

        foreach($data as $value=>$name)

        {

            echo CHtml::tag('option',

                    array('value'=>$value),CHtml::encode($name),true);

        }






Alguém tem algum exemplo funcional da busca usando esse método (findBySql) funcionando (trazendo o campo) ?

Aí verifico se adapto na minha situação aqui

É o resultado de sua consulta.

samjf,

Posta para nos o resultado do var_dump(), quero ver se está retornando objeto ou array.

$posts = NumSequencial::model()->findBySql[…]

var_dump($posts);

Obs.:Cola o resultando dentro da tag [ code ]

Newerton, segue abaixo o resultado do var_dump da variavel posts. No final ele da um erro ao tentar inserir no textfield através do código:




    echo CHtml::textField('valor_maximo', $posts->maximo);



Var_dump $posts:




object(NumSequencial)#59 (12) { ["_md":"CActiveRecord":private]=> object(CActiveRecordMetaData)#46 (5) { ["tableSchema"]=> object(CPgsqlTableSchema)#47 (9) { ["schemaName"]=> string(9) "sch_scspm" ["name"]=> string(17) "tb_num_sequencial" ["rawName"]=> string(31) ""sch_scspm"."tb_num_sequencial"" ["primaryKey"]=> string(17) "id_num_sequencial" ["sequenceName"]=> string(49) "sch_scspm.tb_num_sequencial_id_num_sequencial_seq" ["foreignKeys"]=> array(1) { ["id_tp_num_sequencial"]=> array(2) { [0]=> string(30) "sch_scspm.tb_tp_num_sequencial" [1]=> string(20) "id_tp_num_sequencial" } } ["columns"]=> array(<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/cool.gif' class='bbc_emoticon' alt='8)' /> { ["id_num_sequencial"]=> object(CPgsqlColumnSchema)#51 (14) { ["name"]=> string(17) "id_num_sequencial" ["rawName"]=> string(19) ""id_num_sequencial"" ["allowNull"]=> bool(false) ["dbType"]=> string(7) "integer" ["type"]=> string(7) "integer" ["defaultValue"]=> NULL ["size"]=> NULL ["precision"]=> NULL ["scale"]=> NULL ["isPrimaryKey"]=> bool(true) ["isForeignKey"]=> bool(false) ["autoIncrement"]=> bool(true) ["_e":"CComponent":private]=> NULL ["_m":"CComponent":private]=> NULL } ["num_sequencial_inicial"]=> object(CPgsqlColumnSchema)#52 (14) { ["name"]=> string(22) "num_sequencial_inicial" ["rawName"]=> string(24) ""num_sequencial_inicial"" ["allowNull"]=> bool(false) ["dbType"]=> string(7) "integer" ["type"]=> string(7) "integer" ["defaultValue"]=> NULL ["size"]=> NULL ["precision"]=> NULL ["scale"]=> NULL ["isPrimaryKey"]=> bool(false) ["isForeignKey"]=> bool(false) ["autoIncrement"]=> bool(false) ["_e":"CComponent":private]=> NULL ["_m":"CComponent":private]=> NULL } ["num_sequencial_final"]=> object(CPgsqlColumnSchema)#53 (14) { ["name"]=> string(20) "num_sequencial_final" ["rawName"]=> string(22) ""num_sequencial_final"" ["allowNull"]=> bool(false) ["dbType"]=> string(7) "integer" ["type"]=> string(7) "integer" ["defaultValue"]=> NULL ["size"]=> NULL ["precision"]=> NULL ["scale"]=> NULL ["isPrimaryKey"]=> bool(false) ["isForeignKey"]=> bool(false) ["autoIncrement"]=> bool(false) ["_e":"CComponent":private]=> NULL ["_m":"CComponent":private]=> NULL } ["serie_num_sequencial"]=> object(CPgsqlColumnSchema)#54 (14) { ["name"]=> string(20) "serie_num_sequencial" ["rawName"]=> string(22) ""serie_num_sequencial"" ["allowNull"]=> bool(false) ["dbType"]=> string(20) "character varying(5)" ["type"]=> string(6) "string" ["defaultValue"]=> NULL ["size"]=> int(5) ["precision"]=> int(5) ["scale"]=> NULL ["isPrimaryKey"]=> bool(false) ["isForeignKey"]=> bool(false) ["autoIncrement"]=> bool(false) ["_e":"CComponent":private]=> NULL ["_m":"CComponent":private]=> NULL } ["num_ultimo_registro"]=> object(CPgsqlColumnSchema)#55 (14) { ["name"]=> string(19) "num_ultimo_registro" ["rawName"]=> string(21) ""num_ultimo_registro"" ["allowNull"]=> bool(true) ["dbType"]=> string(7) "integer" ["type"]=> string(7) "integer" ["defaultValue"]=> NULL ["size"]=> NULL ["precision"]=> NULL ["scale"]=> NULL ["isPrimaryKey"]=> bool(false) ["isForeignKey"]=> bool(false) ["autoIncrement"]=> bool(false) ["_e":"CComponent":private]=> NULL ["_m":"CComponent":private]=> NULL } ["dt_num_sequencial"]=> object(CPgsqlColumnSchema)#56 (14) { ["name"]=> string(17) "dt_num_sequencial" ["rawName"]=> string(19) ""dt_num_sequencial"" ["allowNull"]=> bool(false) ["dbType"]=> string(4) "date" ["type"]=> string(6) "string" ["defaultValue"]=> NULL ["size"]=> NULL ["precision"]=> NULL ["scale"]=> NULL ["isPrimaryKey"]=> bool(false) ["isForeignKey"]=> bool(false) ["autoIncrement"]=> bool(false) ["_e":"CComponent":private]=> NULL ["_m":"CComponent":private]=> NULL } ["hr_num_sequencial"]=> object(CPgsqlColumnSchema)#57 (14) { ["name"]=> string(17) "hr_num_sequencial" ["rawName"]=> string(19) ""hr_num_sequencial"" ["allowNull"]=> bool(false) ["dbType"]=> string(22) "time without time zone" ["type"]=> string(6) "string" ["defaultValue"]=> NULL ["size"]=> NULL ["precision"]=> NULL ["scale"]=> NULL ["isPrimaryKey"]=> bool(false) ["isForeignKey"]=> bool(false) ["autoIncrement"]=> bool(false) ["_e":"CComponent":private]=> NULL ["_m":"CComponent":private]=> NULL } ["id_tp_num_sequencial"]=> object(CPgsqlColumnSchema)#58 (14) { ["name"]=> string(20) "id_tp_num_sequencial" ["rawName"]=> string(22) ""id_tp_num_sequencial"" ["allowNull"]=> bool(false) ["dbType"]=> string(7) "integer" ["type"]=> string(7) "integer" ["defaultValue"]=> NULL ["size"]=> NULL ["precision"]=> NULL ["scale"]=> NULL ["isPrimaryKey"]=> bool(false) ["isForeignKey"]=> bool(true) ["autoIncrement"]=> bool(false) ["_e":"CComponent":private]=> NULL ["_m":"CComponent":private]=> NULL } } ["_e":"CComponent":private]=> NULL ["_m":"CComponent":private]=> NULL } ["columns"]=> array(<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/cool.gif' class='bbc_emoticon' alt='8)' /> { ["id_num_sequencial"]=> object(CPgsqlColumnSchema)#51 (14) { ["name"]=> string(17) "id_num_sequencial" ["rawName"]=> string(19) ""id_num_sequencial"" ["allowNull"]=> bool(false) ["dbType"]=> string(7) "integer" ["type"]=> string(7) "integer" ["defaultValue"]=> NULL ["size"]=> NULL ["precision"]=> NULL ["scale"]=> NULL ["isPrimaryKey"]=> bool(true) ["isForeignKey"]=> bool(false) ["autoIncrement"]=> bool(true) ["_e":"CComponent":private]=> NULL ["_m":"CComponent":private]=> NULL } ["num_sequencial_inicial"]=> object(CPgsqlColumnSchema)#52 (14) { ["name"]=> string(22) "num_sequencial_inicial" ["rawName"]=> string(24) ""num_sequencial_inicial"" ["allowNull"]=> bool(false) ["dbType"]=> string(7) "integer" ["type"]=> string(7) "integer" ["defaultValue"]=> NULL ["size"]=> NULL ["precision"]=> NULL ["scale"]=> NULL ["isPrimaryKey"]=> bool(false) ["isForeignKey"]=> bool(false) ["autoIncrement"]=> bool(false) ["_e":"CComponent":private]=> NULL ["_m":"CComponent":private]=> NULL } ["num_sequencial_final"]=> object(CPgsqlColumnSchema)#53 (14) { ["name"]=> string(20) "num_sequencial_final" ["rawName"]=> string(22) ""num_sequencial_final"" ["allowNull"]=> bool(false) ["dbType"]=> string(7) "integer" ["type"]=> string(7) "integer" ["defaultValue"]=> NULL ["size"]=> NULL ["precision"]=> NULL ["scale"]=> NULL ["isPrimaryKey"]=> bool(false) ["isForeignKey"]=> bool(false) ["autoIncrement"]=> bool(false) ["_e":"CComponent":private]=> NULL ["_m":"CComponent":private]=> NULL } ["serie_num_sequencial"]=> object(CPgsqlColumnSchema)#54 (14) { ["name"]=> string(20) "serie_num_sequencial" ["rawName"]=> string(22) ""serie_num_sequencial"" ["allowNull"]=> bool(false) ["dbType"]=> string(20) "character varying(5)" ["type"]=> string(6) "string" ["defaultValue"]=> NULL ["size"]=> int(5) ["precision"]=> int(5) ["scale"]=> NULL ["isPrimaryKey"]=> bool(false) ["isForeignKey"]=> bool(false) ["autoIncrement"]=> bool(false) ["_e":"CComponent":private]=> NULL ["_m":"CComponent":private]=> NULL } ["num_ultimo_registro"]=> object(CPgsqlColumnSchema)#55 (14) { ["name"]=> string(19) "num_ultimo_registro" ["rawName"]=> string(21) ""num_ultimo_registro"" ["allowNull"]=> bool(true) ["dbType"]=> string(7) "integer" ["type"]=> string(7) "integer" ["defaultValue"]=> NULL ["size"]=> NULL ["precision"]=> NULL ["scale"]=> NULL ["isPrimaryKey"]=> bool(false) ["isForeignKey"]=> bool(false) ["autoIncrement"]=> bool(false) ["_e":"CComponent":private]=> NULL ["_m":"CComponent":private]=> NULL } ["dt_num_sequencial"]=> object(CPgsqlColumnSchema)#56 (14) { ["name"]=> string(17) "dt_num_sequencial" ["rawName"]=> string(19) ""dt_num_sequencial"" ["allowNull"]=> bool(false) ["dbType"]=> string(4) "date" ["type"]=> string(6) "string" ["defaultValue"]=> NULL ["size"]=> NULL ["precision"]=> NULL ["scale"]=> NULL ["isPrimaryKey"]=> bool(false) ["isForeignKey"]=> bool(false) ["autoIncrement"]=> bool(false) ["_e":"CComponent":private]=> NULL ["_m":"CComponent":private]=> NULL } ["hr_num_sequencial"]=> object(CPgsqlColumnSchema)#57 (14) { ["name"]=> string(17) "hr_num_sequencial" ["rawName"]=> string(19) ""hr_num_sequencial"" ["allowNull"]=> bool(false) ["dbType"]=> string(22) "time without time zone" ["type"]=> string(6) "string" ["defaultValue"]=> NULL ["size"]=> NULL ["precision"]=> NULL ["scale"]=> NULL ["isPrimaryKey"]=> bool(false) ["isForeignKey"]=>

object(NumSequencial)#59 (12) { ["_md":"CActiveRecord":private]=> object(CActiveRecordMetaData)#46 (5) { ["tableSchema"]=> object(CPgsqlTableSchema)#47 (9) { ["schemaName"]=> string(9) "sch_scspm" ["name"]=> string(17) "tb_num_sequencial" ["rawName"]=> string(31) ""sch_scspm"."tb_num_sequencial"" ["primaryKey"]=> string(17) "id_num_sequencial" ["sequenceName"]=> string(49) "sch_scspm.tb_num_sequencial_id_num_sequencial_seq" ["foreignKeys"]=> array(1) { ["id_tp_num_sequencial"]=> array(2) { [0]=> string(30) "sch_scspm.tb_tp_num_sequencial" [1]=> string(20) "id_tp_num_sequencial" } } ["columns"]=> array(<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/cool.gif' class='bbc_emoticon' alt='8)' /> { ["id_num_sequencial"]=> object(CPgsqlColumnSchema)#51 (14) { ["name"]=> string(17) "id_num_sequencial" ["rawName"]=> string(19) ""id_num_sequencial"" ["allowNull"]=> bool(false) ["dbType"]=> string(7) "integer" ["type"]=> string(7) "integer" ["defaultValue"]=> NULL ["size"]=> NULL ["precision"]=> NULL ["scale"]=> NULL ["isPrimaryKey"]=> bool(true) ["isForeignKey"]=> bool(false) ["autoIncrement"]=> bool(true) ["_e":"CComponent":private]=> NULL ["_m":"CComponent":private]=> NULL } ["num_sequencial_inicial"]=> object(CPgsqlColumnSchema)#52 (14) { ["name"]=> string(22) "num_sequencial_inicial" ["rawName"]=> string(24) ""num_sequencial_inicial"" ["allowNull"]=> bool(false) ["dbType"]=> string(7) "integer" ["type"]=> string(7) "integer" ["defaultValue"]=> NULL ["size"]=> NULL ["precision"]=> NULL ["scale"]=> NULL ["isPrimaryKey"]=> bool(false) ["isForeignKey"]=> bool(false) ["autoIncrement"]=> bool(false) ["_e":"CComponent":private]=> NULL ["_m":"CComponent":private]=> NULL } ["num_sequencial_final"]=> object(CPgsqlColumnSchema)#53 (14) { ["name"]=> string(20) "num_sequencial_final" ["rawName"]=> string(22) ""num_sequencial_final"" ["allowNull"]=> bool(false) ["dbType"]=> string(7) "integer" ["type"]=> string(7) "integer" ["defaultValue"]=> NULL ["size"]=> NULL ["precision"]=> NULL ["scale"]=> NULL ["isPrimaryKey"]=> bool(false) ["isForeignKey"]=> bool(false) ["autoIncrement"]=> bool(false) ["_e":"CComponent":private]=> NULL ["_m":"CComponent":private]=> NULL } ["serie_num_sequencial"]=> object(CPgsqlColumnSchema)#54 (14) { ["name"]=> string(20) "serie_num_sequencial" ["rawName"]=> string(22) ""serie_num_sequencial"" ["allowNull"]=> bool(false) ["dbType"]=> string(20) "character varying(5)" ["type"]=> string(6) "string" ["defaultValue"]=> NULL ["size"]=> int(5) ["precision"]=> int(5) ["scale"]=> NULL ["isPrimaryKey"]=> bool(false) ["isForeignKey"]=> bool(false) ["autoIncrement"]=> bool(false) ["_e":"CComponent":private]=> NULL ["_m":"CComponent":private]=> NULL } ["num_ultimo_registro"]=> object(CPgsqlColumnSchema)#55 (14) { ["name"]=> string(19) "num_ultimo_registro" ["rawName"]=> string(21) ""num_ultimo_registro"" ["allowNull"]=> bool(true) ["dbType"]=> string(7) "integer" ["type"]=> string(7) "integer" ["defaultValue"]=> NULL ["size"]=> NULL ["precision"]=> NULL ["scale"]=> NULL ["isPrimaryKey"]=> bool(false) ["isForeignKey"]=> bool(false) ["autoIncrement"]=> bool(false) ["_e":"CComponent":private]=> NULL ["_m":"CComponent":private]=> NULL } ["dt_num_sequencial"]=> object(CPgsqlColumnSchema)#56 (14) { ["name"]=> string(17) "dt_num_sequencial" ["rawName"]=> string(19) ""dt_num_sequencial"" ["allowNull"]=> bool(false) ["dbType"]=> string(4) "date" ["type"]=> string(6) "string" ["defaultValue"]=> NULL ["size"]=> NULL ["precision"]=> NULL ["scale"]=> NULL ["isPrimaryKey"]=> bool(false) ["isForeignKey"]=> bool(false) ["autoIncrement"]=> bool(false) ["_e":"CComponent":private]=> NULL ["_m":"CComponent":private]=> NULL } ["hr_num_sequencial"]=> object(CPgsqlColumnSchema)#57 (14) { ["name"]=> string(17) "hr_num_sequencial" ["rawName"]=> string(19) ""hr_num_sequencial"" ["allowNull"]=> bool(false) ["dbType"]=> string(22) "time without time zone" ["type"]=> string(6) "string" ["defaultValue"]=> NULL ["size"]=> NULL ["precision"]=> NULL ["scale"]=> NULL ["isPrimaryKey"]=> bool(false) ["isForeignKey"]=> bool(false) ["autoIncrement"]=> bool(false) ["_e":"CComponent":private]=> NULL ["_m":"CComponent":private]=> NULL } ["id_tp_num_sequencial"]=> object(CPgsqlColumnSchema)#58 (14) { ["name"]=> string(20) "id_tp_num_sequencial" ["rawName"]=> string(22) ""id_tp_num_sequencial"" ["allowNull"]=> bool(false) ["dbType"]=> string(7) "integer" ["type"]=> string(7) "integer" ["defaultValue"]=> NULL ["size"]=> NULL ["precision"]=> NULL ["scale"]=> NULL ["isPrimaryKey"]=> bool(false) ["isForeignKey"]=> bool(true) ["autoIncrement"]=> bool(false) ["_e":"CComponent":private]=> NULL ["_m":"CComponent":private]=> NULL } } ["_e":"CComponent":private]=> NULL ["_m":"CComponent":private]=> NULL } ["columns"]=> array(<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/cool.gif' class='bbc_emoticon' alt='8)' /> { ["id_num_sequencial"]=> object(CPgsqlColumnSchema)#51 (14) { ["name"]=> string(17) "id_num_sequencial" ["rawName"]=> string(19) ""id_num_sequencial"" ["allowNull"]=> bool(false) ["dbType"]=> string(7) "integer" ["type"]=> string(7) "integer" ["defaultValue"]=> NULL ["size"]=> NULL ["precision"]=> NULL ["scale"]=> NULL ["isPrimaryKey"]=> bool(true) ["isForeignKey"]=> bool(false) ["autoIncrement"]=> bool(true) ["_e":"CComponent":private]=> NULL ["_m":"CComponent":private]=> NULL } ["num_sequencial_inicial"]=> object(CPgsqlColumnSchema)#52 (14) { ["name"]=> string(22) "num_sequencial_inicial" ["rawName"]=> string(24) ""num_sequencial_inicial"" ["allowNull"]=> bool(false) ["dbType"]=> string(7) "integer" ["type"]=> string(7) "integer" ["defaultValue"]=> NULL ["size"]=> NULL ["precision"]=> NULL ["scale"]=> NULL ["isPrimaryKey"]=> bool(false) ["isForeignKey"]=> bool(false) ["autoIncrement"]=> bool(false) ["_e":"CComponent":private]=> NULL ["_m":"CComponent":private]=> NULL } ["num_sequencial_final"]=> object(CPgsqlColumnSchema)#53 (14) { ["name"]=> string(20) "num_sequencial_final" ["rawName"]=> string(22) ""num_sequencial_final"" ["allowNull"]=> bool(false) ["dbType"]=> string(7) "integer" ["type"]=> string(7) "integer" ["defaultValue"]=> NULL ["size"]=> NULL ["precision"]=> NULL ["scale"]=> NULL ["isPrimaryKey"]=> bool(false) ["isForeignKey"]=> bool(false) ["autoIncrement"]=> bool(false) ["_e":"CComponent":private]=> NULL ["_m":"CComponent":private]=> NULL } ["serie_num_sequencial"]=> object(CPgsqlColumnSchema)#54 (14) { ["name"]=> string(20) "serie_num_sequencial" ["rawName"]=> string(22) ""serie_num_sequencial"" ["allowNull"]=> bool(false) ["dbType"]=> string(20) "character varying(5)" ["type"]=> string(6) "string" ["defaultValue"]=> NULL ["size"]=> int(5) ["precision"]=> int(5) ["scale"]=> NULL ["isPrimaryKey"]=> bool(false) ["isForeignKey"]=> bool(false) ["autoIncrement"]=> bool(false) ["_e":"CComponent":private]=> NULL ["_m":"CComponent":private]=> NULL } ["num_ultimo_registro"]=> object(CPgsqlColumnSchema)#55 (14) { ["name"]=> string(19) "num_ultimo_registro" ["rawName"]=> string(21) ""num_ultimo_registro"" ["allowNull"]=> bool(true) ["dbType"]=> string(7) "integer" ["type"]=> string(7) "integer" ["defaultValue"]=> NULL ["size"]=> NULL ["precision"]=> NULL ["scale"]=> NULL ["isPrimaryKey"]=> bool(false) ["isForeignKey"]=> bool(false) ["autoIncrement"]=> bool(false) ["_e":"CComponent":private]=> NULL ["_m":"CComponent":private]=> NULL } ["dt_num_sequencial"]=> object(CPgsqlColumnSchema)#56 (14) { ["name"]=> string(17) "dt_num_sequencial" ["rawName"]=> string(19) ""dt_num_sequencial"" ["allowNull"]=> bool(false) ["dbType"]=> string(4) "date" ["type"]=> string(6) "string" ["defaultValue"]=> NULL ["size"]=> NULL ["precision"]=> NULL ["scale"]=> NULL ["isPrimaryKey"]=> bool(false) ["isForeignKey"]=> bool(false) ["autoIncrement"]=> bool(false) ["_e":"CComponent":private]=> NULL ["_m":"CComponent":private]=> NULL } ["hr_num_sequencial"]=> object(CPgsqlColumnSchema)#57 (14) { ["name"]=> string(17) "hr_num_sequencial" ["rawName"]=> string(19) ""hr_num_sequencial"" ["allowNull"]=> bool(false) ["dbType"]=> string(22) "time without time zone" ["type"]=> string(6) "string" ["defaultValue"]=> NULL ["size"]=> NULL ["precision"]=> NULL ["scale"]=> NULL ["isPrimaryKey"]=> bool(false) ["isForeignKey"]=>




CException

A propriedade "NumSequencial.maximo" não está definida. (/var/framework/base/CComponent.php:131)

#0 /var/framework/db/ar/CActiveRecord.php(144): CComponent->__get(‘maximo’)

#1 /var/www/scspm-yii/protected/controllers/NumSequencialController.php(193): CActiveRecord->__get(‘maximo’)

#2 /var/framework/web/actions/CInlineAction.php(50): NumSequencialController->actionbuscaultimo()

#3 /var/framework/web/CController.php(309): CInlineAction->runWithParams(Array)

#4 /var/framework/web/filters/CFilterChain.php(134): CController->runAction(Object(CInlineAction))

#5 /var/framework/web/filters/CFilter.php(41): CFilterChain->run()

#6 /var/framework/web/CController.php(1146): CFilter->filter(Object(CFilterChain))

#7 /var/framework/web/filters/CInlineFilter.php(59): CController->filterAccessControl(Object(CFilterChain))

#8 /var/framework/web/filters/CFilterChain.php(131): CInlineFilter->filter(Object(CFilterChain))

#9 /var/framework/web/CController.php(292): CFilterChain->run()

#10 /var/framework/web/CController.php(266): CController->runActionWithFilters(Object(CInlineAction), Array)

#11 /var/framework/web/CWebApplication.php(276): CController->run(‘buscaultimo’)

#12 /var/framework/web/CWebApplication.php(135): CWebApplication->runController(‘NumSequencial/b…’)

#13 /var/framework/base/CApplication.php(162): CWebApplication->processRequest()

#14 /var/www/scspm-yii/index.php(13): CApplication->run()

#15 {main}

CException

A propriedade "NumSequencial.maximo" não está definida. (/var/framework/base/CComponent.php:131)

#0 /var/framework/db/ar/CActiveRecord.php(144): CComponent->__get(‘maximo’)

#1 /var/www/scspm-yii/protected/controllers/NumSequencialController.php(193): CActiveRecord->__get(‘maximo’)

#2 /var/framework/web/actions/CInlineAction.php(50): NumSequencialController->actionbuscaultimo()

#3 /var/framework/web/CController.php(309): CInlineAction->runWithParams(Array)

#4 /var/framework/web/filters/CFilterChain.php(134): CController->runAction(Object(CInlineAction))

#5 /var/framework/web/filters/CFilter.php(41): CFilterChain->run()

#6 /var/framework/web/CController.php(1146): CFilter->filter(Object(CFilterChain))

#7 /var/framework/web/filters/CInlineFilter.php(59): CController->filterAccessControl(Object(CFilterChain))

#8 /var/framework/web/filters/CFilterChain.php(131): CInlineFilter->filter(Object(CFilterChain))

#9 /var/framework/web/CController.php(292): CFilterChain->run()

#10 /var/framework/web/CController.php(266): CController->runActionWithFilters(Object(CInlineAction), Array)

#11 /var/framework/web/CWebApplication.php(276): CController->run(‘buscaultimo’)

#12 /var/framework/web/CWebApplication.php(135): CWebApplication->runController(‘NumSequencial/b…’)

#13 /var/framework/base/CApplication.php(162): CWebApplication->processRequest()

#14 /var/www/scspm-yii/index.php(13): CApplication->run()

#15 {main}

Agora funcionou estava colocando a propriedade no model como private, mudei para public e funcinou.




class NumSequencial extends CActiveRecord

{

    public $maximo;



Mas em relação a segurança? seria interessante deixar como público? ou tenho que criar um método para trazer o maximo (getMaximo()) ?

samjf,

Eu ia falar pra criar a váriavel hehehe

Mais pode deixar como public mesmo sem problema.

Obrigado cara, uma dúvida(agora o problema é outro), estou usando os métodos sem o active (TextField, DropDownList). Com isso o nome dos campos no formulário ficam sem referência ao model e a validação indica que o não campo foi preenchido mesmo se for verdadeiro estou tentando adaptar:

Seria o caso usar activedropDownList ou dropDownList ?

dropDownList funcionando:




echo CHtml::dropDownList('id_tp_num_sequencial', '', CHtml::listData(TpNumSequencial::model()->findAll(), 'id_tp_num_sequencial', 'tp_num_sequencial'), $options);



activedropDownList tentativa




    echo CHtml::activeDropDownList(


                                                 $model,


                                                  'id_tp_num_sequencial',


                                                    CHtml::listData(TpNumSequencial::model()->findAll(), 'id_tp_num_sequencial', 'tp_num_sequencial'), $options

                        )



Pessoal, boa tarde!

Quando criei os textField no Controller usei a tag:




   echo CHtml::textField



Porém, na hora do formulário validar ele não valida, pois não existe o $model como na na view

_form.php:


 

echo $form->textField



O que deve ser feito? Qual a diferença?