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

  • SEARCH
  • Home
  • 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 8996809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:48:16+00:00 2026-06-15T23:48:16+00:00

I have built a simple Notification system in my Cake app that I want

  • 0

I have built a simple Notification system in my Cake app that I want to have a function that will create a new notification when I call a certain method. Because this is not something the user would actually access directly and is only database logic I have put it in the Notification model like so:

class Notification extends AppModel
{
    public $name = 'Notification';

    public function createNotification($userId, $content, $url)
    {
        $this->create();

        $this->request->data['Notification']['user_id'] = $userId;
        $this->request->data['Notification']['content'] = $content;
        $this->request->data['Notification']['url'] = $url;

        $result = $this->save($this->request->data);

        if ($result)
        {
            $this->saveField('datetime', date('Y-m-d H:i:s'));
            $this->saveField('status', 0);
        }
    }
}

And then whenever I want to create a notification within my app I just do:

$this->Notification->createNotification($userId,'Test','Test');

However this doesn’t work! The controller is talking to the model fine, but it doesn’t create the row in the database… I’m not sure why… but it would seem I’m doing this wrong by just doing all the code in the model and then calling it across the app.

Edit: Based on answers and comments below, I have tried the following the code to create a protected method in my notifications controller:

protected function _createNotification($userId, $content, $url)
    {
        $this->Notification->create();

        $this->request->data['Notification']['user_id'] = $userId;
        $this->request->data['Notification']['content'] = $content;
        $this->request->data['Notification']['url'] = $url;

        $result = $this->save($this->request->data);

        if ($result)
        {
            $this->saveField('datetime', date('Y-m-d H:i:s'));
            $this->saveField('status', 0);
        }
    }

Now the thing that is stumping me still (apologies if this is quite simple to others, but I have not used protected methods in CakePHP before) is how do I then call this from another controller? So for example If have a method in my PostsController and want to create a notification on successful save, how would I do this?

I thought about in my PostsController add method:

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

    $this->Notification->_createNotification($userId,'Test','Test');

}

But being protected I wouldn’t be able to access the method from outside of the NotificationsController. Also I’m using the same syntax as if I was calling a function from a model so again it doesn’t feel right.

Hopefully someone can help me out and get me back on track as this is a new area to me.

  • 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-15T23:48:16+00:00Added an answer on June 15, 2026 at 11:48 pm

    Methods in a model are not “publicly accessible” by definition. A user cannot call or invoke a method in a model. A user can only cause a controller action to be initiated, never anything in the model. If you don’t call your model method from any controller, it’s never going to be invoked. So forget about the “non-public” part of the question.

    Your problem is that you’re working in the model as if you were in a controller. There is no request object in a model. You just pass a data array into the model method and save that array. No need for $this->request. Just make a regular array(), put the data that was passed by the controller in there and save it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have built a very simple internal messaging system inside my application, i want
I have built a simple tour on my website that will be coded using
I have built a very simple blog application using Ruby on Rails. New to
I have a simple Android application that uses a JAR I have built. When
I have a simple web app built in asp.net webforms c# where and how
I have built a simple StreamGeometry, using MSDN example: StreamGeometry geometry = new StreamGeometry();
I have built a simple website monitoring application using Indy TIdhttp component. I want
I have a fairly simple app that takes the input from a user and
I have built a simple word addin that interacts with a company intranet. For
I have a fairly complicated notification system that I am working on, it's quite

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.