Communication cakephp habtm (data storage)

The HABTM related question has been posted in some good numbers on stackoverflow, but I'm still looking for a solution to my problem.

I am creating an application that allows you to create themes based on a specific subcategory. When adding a topic, the user requests tags (in the same form). Now that the user has finished adding tags to the topic by clicking the "Add" button, the topic has been successfully added, but there are no tags.

I created a connection table for both themes and tags as tbl_tags_topics.(as defined in cakephp conventions) and correctly defined the hasAndBelongsToMany array in both theme models and tags.

What steps am I missing right now?

I have another question related to this, but I will post it when I can post tags related to the topic to the database. (the functionality is similar to the functionality of adding and attaching stackoverflow tags)

any help is greatly appreciated. also let me know about any good HABTM tutorials if you find them.

thanks

+3
source share
2 answers

With the help of Mr. Stornvig I was able to solve my problem. Here is a link that describes the complete procedure for how to achieve this functionality in cakephp. This is a terrific tutorial to learn more about HABTM relationships.

1.3 , . :

HABTM

echo $form->create('Job');
echo $form->input('title');
echo $form->input('description');
echo $form->input('location');
echo $form->input('Category');//note the caps and single plural
$form->end('Submit');

SaveAll ($ this- > )

.

+3

, :

$this->Model->save(
    'Model' => array('id' => 1, 'name' => 'one random field)
);

, HABTM, :

$this->Model->save(
    'Model' => array('id' => 1, 'name' => 'one random field'),
    'Tag' => array('Tag' => array(1))
);

, , , . , .

, .

, :

$this->Model->habtmAdd('Tag', 1, 1);

"1" - . - .

:

$this->Post->habtmDelete('Tag', 1, 1); 
+5

Source: https://habr.com/ru/post/1720453/


All Articles