如何在蛋糕php中传递url值

时间:2014-04-28 06:46:42

标签: php cakephp

在View / pages / home.ctp

<ul>
 <li><span><?php echo $this->Html->link('Optometrist', array('action'=>'home','9')); ?></span></li>
<li><span><?php echo $this->Html->link('Dentist', array('action'=>'home','10')); ?></span></li>
<ul>

上面的代码我正在传递url值并在同一页面中

<?php 
         if (!empty($users)) {
                            $sl=0;
                            foreach ($users as $row) {

                            //print_r($row);
                                $sl++; ?>
        <div style="width:100%;display:inline-block;">

        <div style="float:left">

            <?php 
        echo $this->Html->link($this->Html->image('../files/user/photo/'.$row['User']['photo_dir'].'/'.$row['User']['photo'], array('width' => '180', 'height' => '180')),
                       array('controller'=>'Profiles','action'=>'index',$row['User']['id']),
                       array('escape' => false));?>


        <?php 

        /*?><a href="profiles/index/<?php echo $row['User']['id']; ?>"><img src="files/user/photo/<?php echo ($row['User']['photo_dir']).'/'.($row['User']['photo']);?>" width="200" height="200"/> </a><?php */?></div>
        <div>
        <?php echo h($row['User']['first_name'])." ".h($row['User']['last_name'])."</br>";
                                echo h($row['User']['username'])."</br>";
                                echo h($row['User']['email'])."</br>";
                                echo h($row['User']['mobile'])."</br>";
                                echo h($row['UserGroup']['name'])."</br>";

                                ?></div>
                                <div style="clear:both;"></div>


                                </div>  <?php } 

                                }?>

</div>

控制器/ PagesController.php

class PagesController extends AppController {

/**
 * This controller does not use a model
 *
 * @var array
 */
    public $uses = array();

/**
 * Displays a view
 *
 * @param mixed What page to display
 * @return void
 * @throws NotFoundException When the view file could not be found
 *  or MissingViewException in debug mode.
 */
 public function display() {
     $this->loadModel('Usermgmt.User');
 //$id=null;
    //for home page
    if(isset($id)){

        $users=$this->User->findByuser_group_id($id);
        $this->set('users', $users);
        }
        else{
        $users=$this->User->find('all');
        $this->set('users', $users);
        }
        /*$users=$this->User->find('all');
        $this->set('users', $users);*/
 //end home page

        $path = func_get_args();

        $count = count($path);
        if (!$count) {
            return $this->redirect('/');
        }
        $page = $subpage = $title_for_layout = null;

        if (!empty($path[0])) {
            $page = $path[0];
        }
        if (!empty($path[1])) {
            $subpage = $path[1];
        }
        if (!empty($path[$count - 1])) {
            $title_for_layout = Inflector::humanize($path[$count - 1]);
        }
        $this->set(compact('page', 'subpage', 'title_for_layout'));

        try {
            $this->render(implode('/', $path));
        } catch (MissingViewException $e) {
            if (Configure::read('debug')) {
                throw $e;
            }
            throw new NotFoundException();
        }
    }
}

这里当我点击菜单if(isset($id)){功能不起作用时显示错误为

缺少视图 错误:找不到PagesController :: display()的视图。 错误:确认您已创建文件:E:\ wamp \ www \ CMS \ app \ View \ Pages \ home \ 9.ctp

2 个答案:

答案 0 :(得分:1)

要为控制器PagesController创建视图,您必须创建名为页面而不是pages的文件夹

它清楚地说:

Missing View Error: The view for PagesController::display() was not found. 
Error: Confirm you have created the file: E:\wamp\www\CMS\app\View\Pages\home\9.ctp

Pages\home\9.ctp此处Pages是文件夹名称case sensitive。因此,请将文件夹名称从pages更改为Pages

这将解决上述错误。

答案 1 :(得分:0)

关于PagesController的Cakephp文档中写了什么 -

CakePHP ships with a default controller `PagesController.php`. This is a simple and optional controller for serving up `static content`.

所以,PagesController适用于静态页面,例如-aboutus,contactus,但不适合动态页面..

类似于www.example.com/{controller}/{action}的网址通常会在action上搜索Controller,但对于PagesController,您不需要定义额外的{action},因为所有网址都是{ {1}}将映射到PagesController操作。

因此,display将映射到显示操作,如果您尝试将任何额外参数传递给url,您将面临该问题......