2011-09-21 76 views
1

我有AA控制器referral_medium_controller.php具有以下內容表單動作鏈接到錯誤的控制器

<?php 
class ReferralMediumsController extends AppController 
{ 
    var $name = 'ReferralMediums'; 

    function admin_index() 
    { 
     //Checking that only super administrators can actually add new interest options 
     if ($this->Auth->user('user_type_id') != ConstUserTypes::Admin) { 
      $this->cakeError('error404'); 
     } 

     $this->pageTitle = __l('Referral Mediums'); 
     $this->ReferralMediums->recursive = 0; 
     $this->set('ReferralMediums', $this->paginate()); 
    } 
    function admin_view($id = null) 
    { 
     //Checking that only super administrators can actually add new interest options 
     if ($this->Auth->user('user_type_id') != ConstUserTypes::Admin) { 
      $this->cakeError('error404'); 
     } 
     $this->pageTitle = __l('Referral Mediums?'); 
     if (is_null($id)) { 
      $this->cakeError('error404'); 
     } 
     $referralMedium = $this->ReferralMediums->find('first', array(
      'conditions' => array(
       'ReferralMedium.id = ' => $id 
      ) , 
      'fields' => array(
       'ReferralMedium.id', 
       'ReferralMedium.created', 
       'ReferralMedium.modified', 
       'ReferralMedium.referral_medium', 
       'ReferralMedium.is_active', 
      ) , 
      'recursive' => -1, 
     )); 
     if (empty($referralMedium)) { 
      $this->cakeError('error404'); 
     } 
     $this->pageTitle.= ' - ' . $referralMedium['ReferralMedium']['id']; 
     $this->set('ReferralMediums', $referralMedium); 
    } 
    function admin_add() 
    { 
     //Checking that only super administrators can actually add new interest options 
     if ($this->Auth->user('user_type_id') != ConstUserTypes::Admin) { 
      $this->cakeError('error404'); 
     } 
     $this->pageTitle = __l('Add Referral Medium'); 
     if (!empty($this->data)) { 
      $this->ReferralMedium->create(); 
      if ($this->ReferralMedium->save($this->data)) { 
       $this->Session->setFlash(__l('Referral Medium has been added') , 'default', null, 'success'); 
       $this->redirect(array(
        'action' => 'index' 
       )); 
      } else { 
       $this->Session->setFlash(__l('Referral Medium could not be added. Please, try again.') , 'default', null, 'error'); 
      } 
     } 
    } 
    function admin_edit($id = null) 
    { 
     //Checking that only super administrators can actually add new interest options 
     if ($this->Auth->user('user_type_id') != ConstUserTypes::Admin) { 
      $this->cakeError('error404'); 
     } 
     $this->pageTitle = __l('Edit Referral Medium'); 
     if (is_null($id)) { 
      $this->cakeError('error404'); 
     } 
     if (!empty($this->data)) { 
      if ($this->ReferralMedium->save($this->data)) { 
       $this->Session->setFlash(__l('Referral Medium has been updated') , 'default', null, 'success'); 
       $this->redirect(array(
        'action' => 'index' 
       )); 
      } else { 
       $this->Session->setFlash(__l('Referral Medium could not be updated. Please, try again.') , 'default', null, 'error'); 
      } 
     } else { 
      $this->data = $this->ReferralMedium->read(null, $id); 
      if (empty($this->data)) { 
       $this->cakeError('error404'); 
      } 
     } 
     $this->pageTitle.= ' - ' . $this->data['ReferralMedium']['id']; 
    } 
    function admin_delete($id = null) 
    { 
     //Checking that only super administrators can actually add new interest options 
     if ($this->Auth->user('user_type_id') != ConstUserTypes::Admin) { 
      $this->cakeError('error404'); 
     } 
     if (is_null($id)) { 
      $this->cakeError('error404'); 
     } 
     if ($this->ReferralMedium->del($id)) { 
      $this->Session->setFlash(__l('Referral Medium deleted') , 'default', null, 'success'); 
      $this->redirect(array(
       'action' => 'index' 
      )); 
     } else { 
      $this->cakeError('error404'); 
     } 
    } 
} 
?> 

具有以下內容

<?php 
class ReferralMedium extends AppModel 
{ 
    var $name = 'ReferralMedium'; 

    var $useTable="referral_mediums"; 

    //$validate set in __construct for multi-language support 
    //The Associations below have been created with all possible keys, those that are not needed can be removed 
    var $hasOne = array(
     'UserProfile' => array(
      'className' => 'UserProfile', 
      'foreignKey' => 'referral_medium_id', 
      'dependent' => false, 
      'conditions' => '', 
      'fields' => '', 
      'order' => '' 
     ) 
    ); 
    var $hasMany = array(
     'UserProfile' => array(
      'className' => 'UserProfile', 
      'foreignKey' => 'referral_medium_id', 
      'dependent' => false, 
      'conditions' => '', 
      'fields' => '', 
      'order' => '', 
      'limit' => '', 
      'offset' => '', 
      'exclusive' => '', 
      'finderQuery' => '', 
      'counterQuery' => '' 
     ) 
    ); 
    function __construct($id = false, $table = null, $ds = null) 
    { 
     parent::__construct($id, $table, $ds); 
     $this->validate = array(
      'referral_medium' => array(
       'rule' => 'notempty', 
       'allowEmpty' => false, 
       'message' => __l('Required') 
      ) , 
     ); 
    } 
} 
?> 

一個附加視圖referral_mediums模型referral_model.php/admin_add.ctp用以下代碼

<?php /* SVN: $Id: $ */ ?> 
<div class="referralMedium form"> 
<?php echo $form->create('ReferralMedium', array('class' => 'normal'));?> 
    <fieldset> 
     <h2><?php echo __l('Add Referral Medium');?></h2> 
    <?php 
     echo $form->input('referral_medium'); 
     echo $form->input('is_active'); 
    ?> 
    </fieldset> 

    <div class="submit-block clearfix"> 
    <?php echo $form->submit(__l('Add'));?> 
    </div> 
    <?php echo $form->end();?> 
</div> 

現在所有工作正常,除非我點擊添加表單中的添加按鈕,我重定向到admin/referral_media/add而不是admin/referral_medium/add,我找不到問題。我會很高興有人可以幫助我。

回答

2

媒體的複數是媒體,而不是媒體。控制器名稱是複數,因此它是referral_media。所以你需要改變你的控制器名稱(和文件名)。

+0

謝謝,我真的需要提高我的英語水平 – Roland

0

或者更改Config/bootstrap.php,這樣就不會使控制器名稱複數了。