Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7743811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:37:49+00:00 2026-06-01T09:37:49+00:00

I have built CMS on cakephp framework. I can delete just one or more

  • 0

I have built CMS on cakephp framework. I can delete just one or more tags not all of them, so how can I delete all the tags from the post.
I have the following files.

Post Model:

<?php
public $displayField = 'title';

public $hasAndBelongsToMany = array(
    'Tag' => array(
        'className' => 'Tag',
        'joinTable' => 'posts_tags',
        'foreignKey' => 'post_id',
        'associationForeignKey' => 'tag_id',
        'unique' => 'keepExisting',
        'conditions' => '',
        'fields' => '',
        'order' => '',
        'limit' => '',
        'offset' => '',
        'finderQuery' => '',
        'deleteQuery' => '',
        'insertQuery' => '',
    )
);

?>

Tag Model:

<?php
public $displayField = 'name';

/**
 * hasAndBelongsToMany associations
 *
 * @var array
 */
public $hasAndBelongsToMany = array(
    'Post' => array(
        'className' => 'Post',
        'joinTable' => 'posts_tags',
        'foreignKey' => 'tag_id',
        'associationForeignKey' => 'post_id',
        'unique' => 'keepExisting',
        'conditions' => '',
        'fields' => '',
        'order' => '',
        'limit' => '',
        'offset' => '',
        'finderQuery' => '',
        'deleteQuery' => '',
        'insertQuery' => ''
    )
);

?>

Post Controller:

<?php
public function admin_edit($id = null) {
    $this->Post->id = $id;
    if (!$this->Post->exists()) {
        throw new NotFoundException(__('Invalid post'));
    }
    if ($this->request->is('post') || $this->request->is('put')) {

        $tags = explode(',', $this->request->data['Post']['tags']);
        foreach ($tags as $_tag) {
            $_tag = strtolower(trim($_tag));
            if ($_tag) {
                $this->Post->Tag->recursive = -1;
                $tag = $this->Post->Tag->findByName($_tag);
                if (!$tag) {
                    $this->Post->Tag->create();
                    $tag = $this->Post->Tag->save(array('name' => $_tag, 'slug' => $_tag));
                    $tag['Tag']['id'] = $this->Post->Tag->id;
                    if (!$tag) {
                        $this->_flash(__(sprintf('The Tag %s could not be saved.', $_tag), true), 'success');
                    }
                }
                if ($tag) {
                    $this->request->data['Tag']['Tag'][$tag['Tag']['id']] = $tag['Tag']['id'];
                }
            }
        }

        if ($this->Post->save($this->request->data)) {

            $this->Session->setFlash(__('The post has been saved'));
            $this->redirect(array('action' => 'index'));
        } else {
            $this->Session->setFlash(__('The post could not be saved. Please, try again.'));
        }
    } else {
        if (empty($this->request->data)) {
            $this->request->data = $this->Post->read(null, $id);
            $tags = array();
            if (isset($this->request->data['Tag']) && !empty($this->request->data['Tag'])) {
                foreach ($this->request->data['Tag'] as $tag) {
                    $tags[] = $tag['name'];
                }
                $this->request->data['Post']['tags'] = implode(', ', $tags);
            }
        }
    }
}

?>

admin_edit.ctp:

echo $this->Form->create('Post');
    echo __('Admin Edit Post');
    echo $this->Form->input('id');
    echo $this->Form->input('user_id');
    echo $this->Form->input('title');
    echo $this->Form->input('slug');
    echo $this->Form->input('content');
    echo $this->Form->input('excerpt');
    echo $this->Form->input('status');
    echo $this->Form->input('comment_status');
    echo $this->Form->input('comment_count');
    echo $this->Form->input('type');
    echo $this->Form->input('Category');
    echo $this->Form->input('Post.tags');
         echo $this->Form->end(__('Submit'));

Thank you for the help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T09:37:50+00:00Added an answer on June 1, 2026 at 9:37 am

    This might help you: http://book.cakephp.org/2.0/en/models/deleting-data.html

    The deleteAll function, you could pass the Posts id and delete all the Tags that are related to it.

    $conditions = array('Tag.id' => 1234);
    $this->Post->Tag->deleteAll($conditions, false);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just inherited a site built on the mojoPortal CMS but we don't have
I have a site complete with CMS etc all working under one domain name.
I have a custom CMS built with ASP.NET WebForms (you can see it in
Our in-house built CMS system has the ability to have descriptive url ( Descriptive
I have a Website, which is built upon a CMS, written in PHP. And
I've inherited a site built with the CMS concrete5. I'm just starting to dissect
We have a CMS built on Java and it has Mozilla Rhino for the
I am creating a custom CMS and have built a login system and was
I have never used a CMS before nor have I built a E-commerce site
Let me elaborate on the question... I have a custom CMS (built on codeigniter

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.