How to make localhost/username/add?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

How to make localhost/username/add?

Eric-133

Hi,

I know how to do like localhost/eric.

But How Can I make fuction add( ) works for localhost/eric/add.

Cause I should pass the param to the add function, i think


--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups "Cake PHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: How to make localhost/username/add?

Eric-133

I got it!  Answer by myself....

1. config the routes.php
add   $Route->connect('/*/add/*', array('controller' => 'users',
'action'=> 'add'));

2. add new function in the users_controller.php
function add($username)
{
        $user = $this->User->findByUsername($username);
        $this->set('user', $user);

        if (!empty($this->data))
    {
        $this->data['Topic']['username']=$username;
        $this->User->Topic->save($this->data);
        {
        $this->_message('Topic saved.',  '/'.$user['User']['username'].'/');
         }
    }
//check the manul abou the Association-Saving models.

3.config the views/users/add.thtml

<form action="<?php echo
$html->url('/'.$user['User']['username'].'/add'); ?>" method="post">
<div class="optional">

        <?php echo $form->labelTag('Topic/name', 'Name');?>
  <?php echo $html->input('Topic/name', array('size' => '60'));?>
  <?php echo $html->hidden('Topic/user_id', array('size' =>
'60','value'=>$user['User']['id']));?>
        <?php echo $html->tagErrorMsg('Topic/name', 'Please enter the
Name.');?>
</div>
<div class="submit">
        <?php echo $html->submit('Add');?>
</div>
</form>

P.S.
To clear abou the Model User and Topic
<?php pr($user)?>
To know the relation and the whole structure.

Loving Cake!!


--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups "Cake PHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: How to make localhost/username/add?

Grant Cox
In reply to this post by Eric-133

I recommend you work through
http://manual.cakephp.org/appendix/blog_tutorial , a lot of these basic
questions will be answered for you.

If you have a function add() in your "eric" controller, you can go to
localhost/eric/add .  In that function look for the existance of
$this->data - whether a form has been submitted.  If not, show the
form.  If so, process the form data.

If you are asking about routes (and eric is a username variable), it
depends on your current route.  Something like $Route->connect
('/:username/:action', array('controller'=>'users'));  would be a start
(off the top of my head, probably won't be right).



On Nov 8, 6:30 pm, "Eric" <[hidden email]> wrote:
> Hi,
>
> I know how to do like localhost/eric.
>
> But How Can I make fuction add( ) works for localhost/eric/add.
>
> Cause I should pass the param to the add function, i think


--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups "Cake PHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---