onclick弹出不在ctp页面页面重定向并显示错误

时间:2014-03-12 06:39:17

标签: cakephp

这里我完成了显示3个选项卡的代码,并在一个选项卡中添加了一个患者详细信息,包括编辑和删除并添加 我试图点击弹出以填充添加患者页面,但它无法正常工作 当我点击页面重定向空页 与

**The requested URL /Projects/DoctorCMS/dashboards/index/onclick:var openWin = window.open('/Projects/DoctorCMS/dashboards/Array', '_blank', 'toolbar=0,scrollbars=1,location=0,status=1,menubar=0,resizable=1,width=500,height=500'); return false; was not found on this server.**

我的代码

应用/控制器/ DashboardsController.php

<?php
class DashboardsController extends AppController {
    public $helpers = array('Html');
    public $components = array('Session');

    public function index() {

     $this-> loadModel('Patientslist');

       $this->set('posts', $this->Patientslist->find('all', array('conditions' => array('Patientslist.user_id' => $this->Auth->user('id')))));



    }
      public function view($id) {
           $this-> loadModel('Patientslist');
        if (!$id) {
            throw new NotFoundException(__('Invalid post'));
        }

        $post = $this->Patientslist->findById($id);

        if (!$post) {
            throw new NotFoundException(__('Invalid post'));
        }
        $this->set('post', $post);

            }
            public function add() {
                 $this-> loadModel('Patientslist');
    if ($this->request->is('post')) {
        //Added this line
        $this->request->data['Patientslist']['user_id'] = $this->Auth->user('id');
        if ($this->Patientslist->save($this->request->data)) {
            $this->Session->setFlash(__('Your post has been saved.'));
            return $this->redirect(array('action' => 'index'));
        }
    }
}

  /*  public function add() {
        if ($this->request->is('post')) {
            $this->Post->create();
            if ($this->Post->save($this->request->data)) {
                $this->Session->setFlash(__('Your post has been saved.'));
                return $this->redirect(array('action' => 'index'));
            }
            $this->Session->setFlash(__('Unable to add your post.'));
        }
    }
    */
    public function edit($id = null) {
         $this-> loadModel('Patientslist');
    if (!$id) {
        throw new NotFoundException(__('Invalid post'));
    }

    $post = $this->Patientslist->findById($id);
    if (!$post) {
        throw new NotFoundException(__('Invalid post'));
    }

    if ($this->request->is(array('Patientslist', 'put'))) {
        $this->Patientslist->id = $id;
        if ($this->Patientslist->save($this->request->data)) {
            $this->Session->setFlash(__('Your post has been updated.'));
            return $this->redirect(array('action' => 'index'));
        }
        $this->Session->setFlash(__('Unable to update your post.'));

    }

    if (!$this->request->data) {
        $this->request->data = $post;
    }
}
public function delete($id) {
     $this-> loadModel('Patientslist');
    if ($this->request->is('get')) {
        throw new MethodNotAllowedException();
    }

    if ($this->Patientslist->delete($id)) {
        $this->Session->setFlash(
            __('The post with id: %s has been deleted.', h($id))
        );
        return $this->redirect(array('action' => 'index'));
    }
}
public function isAuthorized($user) {
     $this-> loadModel('Patientslist');
    // All registered users can add posts
    if ($this->action === 'add') {
        return true;
    }

    // The owner of a post can edit and delete it
    if (in_array($this->action, array('edit', 'delete'))) {
        $postId = $this->request->params['pass'][0];
        if ($this->Patientslist->isOwnedBy($postId, $user['id'])) {
            return true;
        }
    }// 

    return parent::isAuthorized($user);
}
}
?>

应用/视图/仪表板/ index.ctp

<div id="tabs">
  <ul>
    <li><a href="#tabs-1">MyProfile</a></li>
    <li><a href="#tabs-2">Patients</a></li>
    <li><a href="#tabs-3">List</a></li>
  </ul>
  <div id="tabs-1">



  </div>
  <div id="tabs-2">
  <?php 
 // $url=
  echo $this->Html->link('Add Patien', array('onclick'=>"var openWin = window.open('".$this->Html->url(array('controller'=>'dashboards','action'=>'add')."', '_blank', 'toolbar=0,scrollbars=1,location=0,status=1,menubar=0,resizable=1,width=500,height=500');  return false;"))); ?>
  <?php /*?><?php echo $this->Html->link('Add Patien', array('onclick'=>"var openWin = window.open('".$this->url(array('controller'=>'dashboards','action'=>'add')."', '_blank', 'toolbar=0,scrollbars=1,location=0,status=1,menubar=0,resizable=1,width=500,height=500');  return false;"))); ?><?php */?>

  <p><?php  //echo $this->Html->link('Add Patient', array('action' => 'add')); ?></p>
     <table>
    <tr>
        <th>Patient's Name</th>
        <th>Address</th>
        <th>Email-id</th>
        <th>Mobile</th>
        <th>Age</th>
        <th>gender</th>
        <th>Actions</th>
        <th>Created</th>
    </tr>

<!-- Here's where we loop through our $posts array, printing out post info -->

    <?php foreach ($posts as $post): ?>
    <tr>
        <td><?php 
         echo $this->Html->link(
                    $post['Patientslist']['patients_name'],
                    array('action' => 'view', $post['Patientslist']['id'])
                ); ?></td>
        <td>
            <?php
               echo $post['Patientslist']['address'];
            ?>
        </td>
        <td>
            <?php
               echo $post['Patientslist']['email'];
            ?>
        </td>
        <td>
            <?php
               echo $post['Patientslist']['mobile'];
            ?>
        </td>
        <td>
            <?php
               echo $post['Patientslist']['age'];
            ?>
        </td>
        <td>
            <?php
               echo $post['Patientslist']['gender'];
            ?>
        </td>
        <td>
            <?php
                echo $this->Form->postLink( 
                    'Delete',
                    array('action' => 'delete', $post['Patientslist']['id']),
                    array('confirm' => 'Are you sure?')
                );
            ?>
            <?php
                echo $this->Html->link(
                    'Edit', array('action' => 'edit', $post['Patientslist']['id'])
                );
            ?>
        </td>
        <td>
            <?php echo $post['Patientslist']['created']; 
            ?>
        </td>
    </tr>
    <?php endforeach; ?>

</table>
  </div>
  <div id="tabs-3">

  </div>
</div>

add.ctp 代码

<h1>Add Post</h1>
<?php
echo $this->Form->create('Patientslist');
?>
<table>
<tr><h3>Register here</h3></tr>

<tr><td>Patient Name</td><td><?php echo $this->Form->text('patients_name'); ?></td></tr>
<tr><td>Address</td><td><?php echo $this->Form->text('address',array('rows' => '3'));?></td></tr>
<tr><td>Email</td><td><?php echo $this->Form->text('email');?></td></tr>
<tr><td>Mobile</td><td><?php echo $this->Form->text('mobile');?></td></tr>
<tr><td>Age</td><td><?php echo $this->Form->text('age');?></td></tr>
<tr><td>Sex</td><td><?php
$options=array('M'=>'Male','F'=>'Female');
$attributes=array('legend'=>false);
echo $this->Form->radio('gender',$options,$attributes);
?></td></tr>

<tr><td><?php echo $this->Form->end('Save Patientslist');?></td></tr>



</table>

1 个答案:

答案 0 :(得分:1)

您正在将onclick作为网址提供。

echo $this->Html->link('Add Patien', 'javascript:;', array(
    'onclick' => "var openWin = window.open('".$this->Html->url(array('controller'=>'dashboards','action'=>'add'))."', '_blank', 'toolbar=0,scrollbars=1,location=0,status=1,menubar=0,resizable=1,width=500,height=500');  return false;"
));