Include new field in query find () CAKEPHP

1

I have included a new boolean field in a wine table, dist_exclusiva , I have also created the field in the creation and editing form. I have the problem when the queries are executed, it does not pick up the new field, the query seems predefined and I can not find a way to configure it, I understand that it is in the model, but I do not know how to do it. I'm new with CAKEPHP .

This is the controller

  public function admin_edit($id = null) {
    $this->layout = 'admin';
    $title_for_layout  = 'Administrador';
    $title_page = 'Edit Vino';
    $description_page = 'editar Vino del sitio';
    $this->menu[$this->indexmenu]['active'] = true;

    if (!$id) {
        $this->Session->setFlash(__('Please provide el id Vino.'),'flash_notification',array('type'=>'danger','icon'=>'fa-times fa-lg' ));
        $this->redirect(array('action'=>'index'));
    }

    $vino = $this->Vino->findById($id);



    if (!$vino) {
        $this->Session->setFlash(__('Invalid vino ID Provided.'),'flash_notification',array('type'=>'danger','icon'=>'fa-times fa-lg' ));
        $this->redirect(array('action'=>'index'));
    }

    if ($this->request->is('post') || $this->request->is('put')) {
        $this->Vino->id = $id;

        if ($this->request->data['Vino']['imagen']['error'] == 0 && $this->request->data['Vino']['imagen']['size'] > 0){

            // pathes to upload
            //set new name to uplaoded file
            $extcion = ($this->Upload->ext($this->request->data['Vino']['imagen']['name']));
            $NewFileName = $this->Tool->getCodigo().".".$extcion;
            //$NewFileName = $filee['name'];
            // upload file to path
            // here in parameter "image" you can change it that if you want to upload another extension

            if ($this->Upload->upload($this->request->data['Vino']['imagen'], 'img/upload', 'image', $NewFileName, 'vinos'))
                $this->request->data['Vino']['imagen'] = $NewFileName;
            else{
                //set log error if there is problem in uploading
                $this->log(print ('Uploading Error in File'));
            }
        }
        else
            unset($this->request->data['Vino']['imagen']);

        $this->request->data['Vino']['copa'] = str_replace(",", ".", $this->request->data['Vino']['copa']);
        $this->request->data['Vino']['terraza'] = str_replace(",", ".", $this->request->data['Vino']['terraza']);

        if ($this->Vino->save($this->request->data)) {
            $this->Session->setFlash(__('Se actualizo el Vino.'),'flash_notification',array('type'=>'success','icon'=>'fa-check fa-lg' ));
            $this->redirect(array('action' => 'index'));
        }else
            $this->Session->setFlash(__('Unable to update your Vino.'),'flash_notification',array('type'=>'danger','icon'=>'fa-times fa-lg' ));
    }

    if (!$this->request->data) {
        $this->request->data = $vino;
        $this->request->data['Vino']['copa'] = str_replace(".", ",", $vino['Vino']['copa']);
        $this->request->data['Vino']['terraza'] = str_replace(".", ",", $vino['Vino']['terraza']);
    }

    $data = array(
        'menus' => $this->menu
    );

    /*$this->Denominacion->virtualFields = array(
        'full_name' => "CONCAT(Denominacion.nombre, ' / ', Denominacion.descripcion)"
    );*/
    $denominacions = $this->Denominacion->find('list', array('fields' => array('Denominacion.id', 'Denominacion.nombre'), 'order' => array('Denominacion.nombre asc')));
    $cartas = $this->Carta->find('list', array('fields' => array('Carta.id', 'Carta.nombre')));
    $typo = array('Blanco' => 'Blanco', 'Champagne' => 'Champagne', 'Cava' => 'Cava', 'Rosado' => 'Rosado', 'Tinto' => 'Tinto');
    $this->set($data);
    $this->set(compact('typo', 'cartas','denominacions','title_for_layout', 'title_page', 'description_page'));
}

the AppModel

class AppModel extends Model {

    public function generateSlug($title = null, $id = null) {
        if (!$title) {
            throw new NotFoundException(__('Invalid Title'));
        }

        $title = strtolower($title);
        $slug  = Inflector::slug($title, '-');

        $conditions = array();
        $conditions[$this->alias . '.slug'] = $slug;

        if ($id) {
            $conditions[$this->primaryKey. ' NOT'] = $id;
        }

        $total = $this->find('count', array('conditions' => $conditions, 'recursive' => 0));
        if ($total > 0) {
            for ($number = 2; $number > 0; $number ++) {
                $conditions[$this->alias . '.slug'] = $slug . '-' . $number;

                $total = $this->find('count', array('conditions' => $conditions, 'recursive' => 0));
                if ($total == 0) {
                    return $slug . '-' . $number;
                }
            }
        }

        return $slug;
    }
}

the model

class Vino extends AppModel {

var $name = 'Vino';

var $belongsTo = array(
    'Carta' => array(
        'className'    => 'Carta',
        'foreignKey'   => 'carta_id'
    ),
    'Denominacion' => array(
        'className'    => 'Denominacion',
        'foreignKey'   => 'denominacion_id'
    )
);

Thanks in advance

I add a view of the form

   <div class="page-header">
<h1>
    <?php echo $title_page ?>
    <small>
        <i class="ace-icon fa fa-angle-double-right"></i>
        <?php echo $description_page ?>
    </small>
</h1>
</div><!-- /.page-header -->

<div class="row">
  <div class="col-xs-12">
    <!-- PAGE CONTENT BEGINS -->
    <?php echo $this->Form->create('Vino', array('type' => 'file', 'class' => 'form-horizontal', 'role' => 'form','id' => 'myform', 'action' => 'add'));?>
    <!-- #section:elements.form -->
    <div class="form-group">
        <label class="col-sm-3 control-label no-padding-right">Vino</label>
        <?php echo $this->Form->input('bodega', array('div' => 'col-sm-9', 'label' => false, 'class' => 'col-xs-10 col-sm-5', 'placeholder' => 'bodega...', 'type' => 'text', 'required' => true)); ?>
    </div>
    <div class="space-4"></div>
    <div class="form-group">
        <label class="col-sm-3 control-label no-padding-right">Bodega</label>
        <?php echo $this->Form->input('lugar', array('div' => 'col-sm-9', 'label' => false, 'class' => 'col-xs-10 col-sm-5', 'placeholder' => 'lugar...', 'type' => 'text')); ?>
    </div>
    <div class="space-4"></div>
    <div class="form-group">
        <label class="col-sm-3 control-label no-padding-right">Crianza</label>
        <?php echo $this->Form->input('crianza', array('div' => 'col-sm-9', 'label' => false, 'class' => 'col-xs-10 col-sm-5', 'placeholder' => 'crianza', 'type' => 'text')); ?>
    </div>
    <div class="space-4"></div>
    <div class="form-group">
        <label class="col-sm-3 control-label no-padding-right">uva</label>
        <?php echo $this->Form->input('grapes', array('div' => 'col-sm-9', 'label' => false, 'class' => 'col-xs-10 col-sm-5', 'placeholder' => 'graprs', 'type' => 'text')); ?>
    </div>
    <div class="space-4"></div>
    <div class="form-group">
        <label class="col-sm-3 control-label no-padding-right">Botella</label>
        <?php echo $this->Form->input('precio', array('div' => 'col-sm-9', 'label' => false, 'class' => 'col-xs-10 col-sm-5', 'placeholder' => 'Precio...', 'type' => 'text')); ?>
    </div>
    <div class="space-4"></div>
    <div class="form-group">
        <label class="col-sm-3 control-label no-padding-right">Copa</label>
        <?php echo $this->Form->input('copa', array('div' => 'col-sm-9', 'label' => false, 'class' => 'col-xs-10 col-sm-5', 'placeholder' => 'Copa...', 'type' => 'text')); ?>
    </div>
    <!--div class="space-4"></div>
    <div class="form-group">
        <label class="col-sm-3 control-label no-padding-right">Tienda</label>
        <?php echo $this->Form->input('terraza', array('div' => 'col-sm-9', 'label' => false, 'class' => 'col-xs-10 col-sm-5', 'placeholder' => 'Terraza...', 'type' => 'text')); ?>
    </div-->
    <div class="space-4"></div>
    <div class="form-group">
        <label class="col-sm-3 control-label no-padding-right">Distribucion</label>
        <?php echo $this->Form->input('hosteleria', array('div' => 'col-sm-9', 'label' => false, 'class' => 'col-xs-10 col-sm-5', 'placeholder' => 'Distribucion...', 'type' => 'text')); ?>
    </div>


    <div class="space-4"></div>
    <div class="form-group">
        <label class="col-sm-3 control-label no-padding-right" for="categoria">Distribución Exclusiva</label>
        <div class="col-sm-9">
            <?php echo $this->Form->input('dist_exclusiva',array('label'=> false, 'class' => "", 'type'=>'checkbox')); ?>
        </div>
    </div>



    <div class="space-4"></div>
    <div class="form-group">
        <label class="col-sm-3 control-label no-padding-right">Eno-precio</label>
        <?php echo $this->Form->input('enoprecio', array('div' => 'col-sm-9', 'label' => false, 'class' => 'col-xs-10 col-sm-5', 'placeholder' => 'Eno-precio...', 'type' => 'text')); ?>
    </div>
    <div class="space-4"></div>
    <div class="form-group">
        <label class="col-sm-3 control-label no-padding-right">Outlet</label>
        <?php echo $this->Form->input('outlet', array('div' => 'col-sm-9', 'label' => false, 'class' => 'col-xs-10 col-sm-5', 'placeholder' => 'Outlet...', 'type' => 'text')); ?>
    </div>
    <div class="space-4"></div>
    <div class="form-group">
        <label class="col-sm-3 control-label no-padding-right" for="categoria">Tipo</label>
        <div class="col-sm-9">
            <?php echo $this->Form->input('typo',array('label'=> false, 'class' => "col-xs-10 col-sm-5", 'type'=>'select', 'options' => $typo, 'required' => true)); ?>
        </div>
    </div>
    <div class="space-4"></div>
    <div class="form-group">
        <label class="col-sm-3 control-label no-padding-right" for="categoria">Carta</label>
        <div class="col-sm-9">
            <?php echo $this->Form->input('carta_id',array('label'=> false, 'name' => "data[Vino][carta_id]", 'empty' => array(0 => ''), 'class' => "col-xs-10 col-sm-5", 'type'=>'select')); ?>
        </div>
    </div>
    <div class="space-4"></div>
    <div class="form-group">
        <label class="col-sm-3 control-label no-padding-right" for="categoria">Denominacion</label>
        <div class="col-sm-9">
            <?php echo $this->Form->input('denominacion_id',array('label'=> false, 'class' => "col-xs-10 col-sm-5", 'type'=>'select', 'required' => true)); ?>
        </div>
    </div>
    <div class="space-4"></div>
    <div class="form-group">
        <label class="col-sm-3 control-label no-padding-right" for="categoria">Add Carta texto</label>
        <div class="col-sm-9">
            <?php echo $this->Form->input('add_carta',array('label'=> false, 'class' => "", 'type'=>'checkbox')); ?>
        </div>
    </div>
    <div class="space-4"></div>
    <div class="form-group">
        <label class="col-sm-3 control-label no-padding-right" for="categoria">Add Tv</label>
        <div class="col-sm-9">
            <?php echo $this->Form->input('add_tv',array('label'=> false, 'class' => "", 'type'=>'checkbox')); ?>
        </div>
    </div>
    <div class="space-4"></div>
    <div class="form-group">
        <label class="col-sm-3 control-label no-padding-right">Imagen</label>
        <?php if(!empty($this->data['Vino']['imagen'])):
            echo $this->Form->input('imagen', array('div' => 'col-sm-9', 'label' => false, 'class' => 'col-xs-10 col-sm-5 logo file-loading', 'type' => 'file', 'accept' => 'image/*', 'data-buttonText' => "Find file"));
        else:
            echo $this->Form->input('imagen', array('div' => 'col-sm-9', 'label' => false, 'class' => 'col-xs-10 col-sm-5 logo file-loading', 'type' => 'file', 'accept' => 'image/*', 'data-buttonText' => "Find file", 'required' => true));
        endif;
        ?>
    </div>
    <div class="space-4"></div>
    <div class="form-group">
        <label class="col-sm-3 control-label no-padding-right">Descripción</label>
        <div class="col-sm-9">
            <?php echo $this->Form->textarea('description', array('div' => 'col-sm-9', 'label' => false, 'class' => 'col-xs-10 col-sm-5', 'placeholder' => 'texto...', 'rows' => 8)); ?>
        </div>
    </div>
    <div class="space-4"></div>
    <div class="clearfix form-actions">
        <div class="col-md-offset-3 col-md-9">
            <button class="btn btn-info" type="submit">
                <i class="ace-icon fa fa-check bigger-110"></i>
                Guardar
            </button>
            &nbsp; &nbsp; &nbsp;
            <button class="btn resetform" type="reset">
                <i class="ace-icon fa fa-undo bigger-110"></i>
                Reset
            </button>
        </div>
    </div>
    <?php echo $this->Form->end(); ?>
 </div><!-- /.col -->
</div><!-- /.row -->
    
asked by user9092634 29.01.2018 в 16:31
source

1 answer

1

When you add a new field in the database you must delete the cache memory of the model so that it can take the change, then add the inputs in your view add and edit with the name you saved the field. < br> It is also good practice to remove the browser cache.

You can go to the app / tmp / cache / models route and delete or by console with the following commands

rm -f app/tmp/cache/models/*

rm -f app/tmp/cache/views/*

you add this in the views

 <?php echo $this->Form->input('dist_exclusiva',array('label'=> false, 'class' => "", 'type'=>'checkbox')); ?>
    
answered by 05.09.2018 / 21:41
source