I have a a controller referral_medium_controller.php
with the following content
<?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-&开发者_StackOverflow中文版gt;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');
}
}
}
?>
a model referral_model.php with the following content
<?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')
) ,
);
}
}
?>
a add view referral_mediums/admin_add.ctp with the following code
<?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>
Now all works fine except if I click on the add button in the add form I get redirected to admin/referral_media/add instead of admin/referral_medium/add and I can't find the problem. I would be greatful I someone could help me with this.
the plural of medium is media, not mediums. The controller name is plural, so it's referral_media. So you'll need to change your controller name (and the file name).
Or change Config/bootstrap.php so it won't make controller names plural anymore.
精彩评论