Yes - because it's coming from the URL it's not *strictly* necessary
to redefine it in your controller, but defining it in the controller
is generally better coding style because the explicit relationship is
easier to see at-a-glance. It also means that you're better able to do
checks on the id number, for example:
function index($id = null){
if (!$id) {
$this->set('model', $this->Model->read(null, '1'));
} else {
if(!is_numeric($id)) {
$this->set('model', $this->Model->read(null,
'1'));
} else {
$this->set('model', $this->Model->read(null,
$id));
}
}
}
It's really just a style of coding that increases clarity (or not, as
the case may be ;) ).
On Sep 19, 4:49 pm, lorenx <[email protected]> wrote:
> > 1. Cake's reading the id from the url. You're saying, in the url,
> > 'show me the Post controller / the View method / and record number
> > #n', and Cake's handling that for you automatically.
>
> sure but... what if i comment out all the $id reference?
> this cleaned code:
> function view() {
> $this->set('post', $this->Post->read());}
>
> continues to work properly; it seems that the $this->Post->id=$id
> assignment is not necessary...
>
> > 2. Post/Somefunction only becomes a valid URL if you make a
> > corresponding view file for it. You can, if you want, use private
> > methods by marking a method with a preceding underscore, so:
>
> > _method() { //code }
>
> > That'll make the method only accessible to other methods within the
> > controller. You can also use routes to redirect users around if they
> > try to access a method through the url that they shouldn't be using.
>
> perfect.
>
> thanks...
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---