Cakephp Classroom image

pankaj
 
To post your Question Join Classroom
 
Lesson Topics's No:-  First|2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10|Last
Lessons:-Controllers

Rendering a specific view
In your controller you may want to render a different view than what would conventionally be done. You can
do this by calling render() directly. Once you have called render() CakePHP will not try to re-render
the view:
class PostsController extends AppController {
public function my_action() {
$this->render(’custom_file’);
}
}
This would render app/View/Posts/custom_file.ctp instead of
app/View/Posts/my_action.ctpFlow Control
Controller::redirect(mixed $url, integer $status, boolean $exit)
The flow control method you’ll use most often is redirect(). This method takes its first parameter
in the form of a CakePHP-relative URL. When a user has successfully placed an order, you might wish
to redirect them to a receipt screen.:
public function place_order() {
// Logic for finalizing order goes here
if ($success) {
$this->redirect(array(’controller’ => ’orders’, ’action’ => ’thanks’));
} else {
$this->redirect(array(’controller’ => ’orders’, ’action’ => ’confirm’));
}
}
You can also use a relative or absolute URL as the $url argument:
$this->redirect(’/orders/thanks’));
$this->redirect(’http://www.example.com’);
You can also pass data to the action:
$this->redirect(array(’action’ => ’edit’, $id));
The second parameter of redirect() allows you to define an HTTP status code to accompany the
redirect. You may want to use 301 (moved permanently) or 303 (see other), depending on the nature
of the redirect.
The method will issue an exit() after the redirect unless you set the third parameter to false.
If you need to redirect to the referer page you can use:
$this->redirect($this->referer());
The method also supports name based parameters. If you want to redirect to a URL
like: http://www.example.com/orders/confirm/product:pizza/quantity:5
you can use:
$this->redirect(array(’controller’ => ’orders’, ’action’ => ’confirm’, ’product’ => ’pizza’, Controller::flash(string $message, string $url, integer $pause, string $layout)
Like redirect(), the flash() method is used to direct a user to a new page after an operation.
The flash() method is different in that it shows a message before passing the user on to another
URL.
The first parameter should hold the message to be displayed, and the second parameter is a CakePHPrelative
URL. CakePHP will display the $message for $pause seconds before forwarding the user
on.
If there’s a particular template you’d like your flashed message to use, you may specify the name of
that layout in the $layout parameter.
For in-page flash messages, be sure to check out SessionComponent’s setFlash() method.

 
 
 

pankaj

Skills    Cakephp

Qualifications :-
Location :-,,,
Description:-
Explore
 

  Students (0)