Outputting a hyperlink from a controller in cakePHP?

The idea is that all the data you need to render the page is sent to the view with set, then any conditional logic or formatting is done in the view with helpers, so send whole query results when appropriate (suppose you need to alter a link to include the user's screen name, you'll have it handy) in controller action $this->set('user', $this->User) in view (this is slightly different depending on if your in id) //available because of Controller->set { //1.2 $link = $html->link(__("Please log in", TRUE), array('controller' => "users", 'action' => "login" )); //1.3 $link = $this->Html->link(__("Please log in", TRUE), array('controller' => "users", 'action' => "login" )); echo __("Your email address has been confirmed. ", TRUE). " $link"; } else { $this->set('message', __("Please check your mail for the correct URL to confirm your account", TRUE)); }.

The idea is that all the data you need to render the page is sent to the view with set, then any conditional logic or formatting is done in the view with helpers, so send whole query results when appropriate (suppose you need to alter a link to include the user's screen name, you'll have it handy). In controller action $this->set('user', $this->User); in view (this is slightly different depending on if your in id) //available because of Controller->set { //1.2 $link = $html->link(__("Please log in", TRUE), array('controller' => "users", 'action' => "login" )); //1.3 $link = $this->Html->link(__("Please log in", TRUE), array('controller' => "users", 'action' => "login" )); echo __("Your email address has been confirmed. ", TRUE)." $link"; } else { $this->set('message', __("Please check your mail for the correct URL to confirm your account", TRUE)); }.

Aaah, ok! That makes a bit more sense. It was the idea of passing the full user data to the view that I didn't get.

I saw the view as far more "dumb". Thanks for the good clear illustration. – ppyjim Sep 28 '10 at 7:09 how can you tell someone to pass the User model to the view?

That is breaking MVC in the biggest way ive seen. – dogmatic69 Sep 28 '10 at 19:18 I thought $this->User was as query result rather than a model. Your right, you should be doing $user = $this->User->find() then $this->set('user', $user) , so user would be a result array in the view.

– Lincoln B Sep 29 '10 at 6:57 Yeah, I understood it to be the data, rather than the model - passing the model could risk all sorts of nasty circular references happening, right? (not to mention breaking the MVC) – ppyjim Sep 30 '10 at 12:40.

You're not supposed to use Helpers in the Controller. As @Lincoln pointed out, you should construct the link in the View. You may construct the URL in the Controller, since a URL is basically data, but a link is a very medium-specific (HTML) implementation of a URL.

Either way, you'll need to create a full URL (including host) if you want to send it in an Email. The most universal way is to use Router::url: $fullUrl = Router::url(array('controller' => ...), true); // 'true' for full URL Do this in either the Controller or the View. For creating a link, use this in the View: echo $html->link('Title', $fullUrl).

What you are trying to do should be done with the SessionComponent. $this->Session->setFlash('your message here'); and in your layout with the session helper put $this->Session->flash(); About your wanting urls in the controller, Router::url is correct as deceze said, but there is no use for it there as you should not be building html in a controller. What you want to do it use the session::setFlash() method above and then redirect them using $this->redirect(array('controller' => "users", 'action' => "login" )).

Thanks for the pointers - but in this case the flash isn't enough, as there's more than just a single "div" to populate - I just kinda cut the code down for the example. Either way, letting the view handle the display logic makes much more sense to me, and I've gotten the code working. – ppyjim Sep 30 '10 at 12:38.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions