On Mon, Nov 8, 2010 at 5:46 PM, [email protected] <[email protected]> wrote:
> Hi guys, I'm new to this,... and make a long story short I bought an
> incomplete social network script... I need to add videos, blogs,
> groups,... etc... and having problem to categories them... Found you
> here in Google Groups,... What a great place to be... Thank you in
> advance for your help and effort... Here we go...
> What I have is:
>
> <?php
> class Video extends AppModel {
>    var $name = 'Video';
>
>         var $validate = array(
>    'video_title' => VALID_NOT_EMPTY,
>    'user_id' => VALID_NOT_EMPTY,
>    'category_id' => VALID_NOT_EMPTY,
>    'video_description' => VALID_NOT_EMPTY,
>    'video_embed_code' => VALID_NOT_EMPTY
>        );

It looks like you're using an older version of Cake. You'll need to
take care that any advice you receive, or find online, corresponds to
your version. In any case, VALID_NOT_EMPTY has been deprecated. See
this page for the latest:

http://book.cakephp.org/view/1152/Core-Validation-Rules

I suggest, if at all possible, you upgrade to 1.3.5. It'll mean a few
modifications but it'll be worth it.


>        var $belongsTo = array(
>                'VideoCategory' => array(
>                        'className'     => 'VideoCategory',
>                        'foreignKey'    => 'category_id'
>                ),
>                'User' => array(
>                        'className'     => 'User',
>                        'foreignKey'    => 'id'
>                )
>        );
>
>        var $hasMany = array(
>                'VideoComment' => array(
>                        'className'     => 'VideoComment',
>                        'foreignKey'    => 'video_id'
>                ),
>                'User' => array(
>                        'className'     => 'User',
>                        'foreignKey'    => 'id'
>                )
>        );
>
> }
> ?>
>
> and
>
> <?php
> class VideoCategory extends AppModel {
>  var $name = 'VideoCategory';
>
>  var $validate = array(
>    'id' => VALID_NOT_EMPTY,
>    'category_name' => VALID_NOT_EMPTY
>  );
>
>
> }
> ?>
>
> in models....
>
> I like to know how to display these categories in <form> fields e.g.
> <?php echo $form->select('Video/category'), ..... and how to post that
> video to belong to that category....  and  what I need to have in
> videos_controller.php and .../views/videos/add.ctp for select box.

The easiest way is to use find('list'), which returns an array in the
form, $id => $name, and can be passed to the FormHelper to create a
select list.

Videosontroller:

function edit($id = null)
{
        if (!$id)
        {
                // set Flash msg and redirect
        }
        
        if (!empty($this->data))
        {
                // check validation, save, redirect if saved
        }
        
        $this->set(
                'categories',
                $this->Video->VideoCategory->find('list')
        );
}

view:

echo $form->select('Video.category_id', $categories);

Actually, now that I think about it, FormHelper didn't exist in
version 1.1.x, I think. But that's the basic idea in 1.2.x.
http://book.cakephp.org/view/305/The-Manual

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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

Reply via email to