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.
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.
3. Be careful with that - the $form->something syntax is used only by
the form helper. Cake will automatically build your form inputs so
long as you name them properly, so if you've got $form->input
('Model.fieldname'); then Cake will work its magic on that field and
model. In your edit example, $this->data is the array that's retrieved
from the form - in the edit.ctp file itself, the form should work like
$form->input('Model.fieldname');
If you want to just display your data without the form helper, then
you can use the set method in the controller:
$this->set(array('mytitle'=>$this->data['Post']['title']));
This makes a variable called $mytitle available to the view template
with the contents of $this->data['Post']['title'] in it.
On Sep 19, 3:27 pm, lorenx <[email protected]> wrote:
> thanks to all!
> ...but i still have some doubts.
>
> 1.
> if i write:
> function view() {
> $this->set('post', $this->Post->read());}
>
> then the urls post/view/1 and post/view/2 continue to show
> respectively post n.1 and post n.2, i cannot understand how (maybe i
> have to look depper in the code)
>
> 2.
> ok but... if i have two identical pieces of code and i extract them in
> someFunction() then post/someFunction becomes a valid url?
> if so, how to avoid this behaviour?
>
> 3.
> ok. so $this->data in the controller becomes $form->data in the
> respective ctp file.
>
> thanks again to all!
>
> On Sep 18, 9:13 pm, Hols Kay <[email protected]> wrote:
>
> > 1. $this->Post->id = $id sets the model id field to whatever the id is
> > that you've passed in the URL. That's retained for the $this->Post->read();
> > underneath it. You can also say things like $this->set
>
> > ('post', $this->Post->read(null, $id)); to read all the fields for
> > record $id, for example, instead of assigning the id and then reading
> > it.
>
> > 2. Every function in the controller IS a method, and every method IS
> > an action ;) They're all synonyms for the same thing. You don't need a
> > view for every controller method, only the ones that you'll logically
> > want a view for, which is what I think you're meaning to ask.
>
> > 3. $this->data is handled automagically by Cake. It consists of an
> > array of the data that you're moving from one place to another, so you
> > can act on specific fields by calling $this->data['Model']['field'].
>
> > Hope this helps!
>
> > On Sep 17, 7:05 pm, lorenx <[email protected]> wrote:
>
> > > hi all,
> > > i'm new to cakephp and, mentioning the blog tutorial, i have some
> > > simple questions.
>
> > > 1.
> > > in the sample controller, there is the view action:
>
> > > function view($id = null) {
> > > $this->Post->id = $id;
> > > $this->set('post', $this->Post->read());
>
> > > }
>
> > > to better understand, i did some tests.
> > > i tried to comment out the passed parameter $id and the
> > > $this->Post->id=$id assignment... and the code seems to work as before.
>
> > > i also printed_r the Post object, before and after that line, but no
> > > change appeared.
> > > so... what exactly do the assignment? and passing the $_GET parameter
> > > is necessary?
>
> > > 2.
> > > does every function in the controller involve the creation of a
> > > method, of an action?
>
> > > 3.
> > > in the edit action, there is the $this->data variable.
> > > i presume that this variable is going to populate the edit form. how
> > > is this handled?
>
> > > thanks to all!
>
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---