cakephp displayfield混淆了吗?

时间:2014-01-10 20:37:31

标签: cakephp model

我正在cakephp 2.0中创建一个小应用程序

我有树模型DescCriter属于Aspects,Aspects属于Activits,Activits属于计划

我改变所有模型public $ displayField ='descripcion';

但是我想要显示与id不同的东西..在我看来我不能......

我不修复......我唯一能看到的就是id

添加型号代码

class DescCriter extends AppModel {
   public $displayField = 'Criterio'; 
    public $validate = array(
        'aspects_id' => array(
            'numeric' => array(
                'rule' => array('numeric'),
                //'message' => 'Your custom message here',
                //'allowEmpty' => false,
                //'required' => false,
                //'last' => false, // Stop validation after this rule
                //'on' => 'create', // Limit validation to 'create' or 'update' operations
            ),
        ),
    );

    public $belongsTo = array(
        'Aspects' => array(
            'className' => 'Aspects',
            'foreignKey' => 'aspects_id',
            'conditions' => '',
            'fields' => '',
            'order' => ''
        )
    );


class Aspect extends AppModel {

    public $displayField = 'descripcion';
    public $validate = array(
        'activits_id' => array(
            'numeric' => array(
                'rule' => array('numeric'),
                //'message' => 'Your custom message here',
                //'allowEmpty' => false,
                //'required' => false,
                //'last' => false, // Stop validation after this rule
                //'on' => 'create', // Limit validation to 'create' or 'update' operations
            ),
        ),
    );

    //The Associations below have been created with all possible keys, those that are not needed can be removed


    public $belongsTo = array(
        'Activits' => array(
            'className' => 'Activits',
            'foreignKey' => 'activits_id',
            'conditions' => '',
            'fields' => '',
            'order' => ''
        )
    );

class Activit extends AppModel {

   public $displayField = 'descripcion'; 
    public $validate = array(
        'plans_id' => array(
            'numeric' => array(
                'rule' => array('numeric'),
                //'message' => 'Your custom message here',
                //'allowEmpty' => false,
                //'required' => false,
                //'last' => false, // Stop validation after this rule
                //'on' => 'create', // Limit validation to 'create' or 'update' operations
            ),
        ),
    );


    public $belongsTo = array(
        'Plans' => array(
            'className' => 'Plans',
            'foreignKey' => 'plans_id',
            'conditions' => '',
            'fields' => '',
            'order' => ''
        )
    );

// controler aspects

public function add() {
        if ($this->request->is('post')) {
            $this->Activit->create();
            if ($this->Activit->save($this->request->data)) {
                $this->Session->setFlash(__('The activit has been saved'));
                $this->redirect(array('action' => 'index'));
            } else {
                $this->Session->setFlash(__('The activit could not be saved. Please, try again.'));
            }
        }
        $plans = $this->Activit->Plans->find('list');

        $this->set(compact('plans'));
    }

// controler Activitis

 public function add() {
            if ($this->request->is('post')) {
                $this->Aspect->create();
                if ($this->Aspect->save($this->request->data)) {
                    $this->Session->setFlash(__('The aspect has been saved'));
                    $this->redirect(array('action' => 'index'));
                } else {
                    $this->Session->setFlash(__('The aspect could not be saved. Please, try again.'));
                }
            }
            $activits = $this->Aspect->Activits->find('list');
            $this->set(compact('activits'));
        }

//查看方面添加

<div class="aspects form">
<?php echo $this->Form->create('Aspect'); ?>
    <fieldset>
        <legend><?php echo __('Add Aspect'); ?></legend>
    <?php
        echo $this->Form->input('descripcion');
        echo $this->Form->input('activits_id');
    ?>
    </fieldset>
<?php echo $this->Form->end(__('Submit')); ?>
</div>
<div class="actions">
    <h3><?php echo __('Actions'); ?></h3>
    <ul>

        <li><?php echo $this->Html->link(__('List Aspects'), array('action' => 'index')); ?></li>
        <li><?php echo $this->Html->link(__('List Activits'), array('controller' => 'activits', 'action' => 'index')); ?> </li>
        <li><?php echo $this->Html->link(__('New Activits'), array('controller' => 'activits', 'action' => 'add')); ?> </li>
    </ul>
</div>

//查看活动添加

<div class="activits form">
<?php echo $this->Form->create('Activit'); ?>
    <fieldset>
        <legend><?php echo __('Add Activit'); ?></legend>
    <?php
        echo $this->Form->input('descripcion');
        echo $this->Form->input('plans_id');
    ?>
    </fieldset>
<?php echo $this->Form->end(__('Submit')); ?>
</div>
<div class="actions">
    <h3><?php echo __('Actions'); ?></h3>
    <ul>

        <li><?php echo $this->Html->link(__('List Activits'), array('action' => 'index')); ?></li>
        <li><?php echo $this->Html->link(__('List Plans'), array('controller' => 'plans', 'action' => 'index')); ?> </li>
        <li><?php echo $this->Html->link(__('New Plans'), array('controller' => 'plans', 'action' => 'add')); ?> </li>
    </ul>
</div>

0 个答案:

没有答案