papa.ramu
papa.ramu

Reputation: 423

how to pass url value in cake php

in 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>

above code i am passing url value and in samepage

<?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>

Controller/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();
        }
    }
}

here when i click the menu if(isset($id)){ function not working shows error as

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

Upvotes: 1

Views: 1408

Answers (2)

Fazal Rasel
Fazal Rasel

Reputation: 4526

What written on Cakephp documentation about PagesController is-

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

So, PagesController is good for static pages like-aboutus, contactus something but not good for dynamic pages..

A url like www.example.com/{controller}/{action} Generally search for action on Controller but for PagesController you don't need to define extra {action} because all url to PagesController will map to display action.

So, www.example.com/pages/about_us will map to display action and if you try to pass any extra argument to url, you will face that problem...

Upvotes: 0

sandip
sandip

Reputation: 3289

For creating views for controller PagesController, you have to create folder named Pages not pages

It clearly says:

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 here Pages is the folder name that is case sensitive. So change the folder name from pages to Pages.

This will solve the above error.

Upvotes: 1

Related Questions