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 8867307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T16:59:45+00:00 2026-06-14T16:59:45+00:00

I am creating a custom validation function in my model in CakePHP. After reading

  • 0

I am creating a custom validation function in my model in CakePHP. After reading similar questions I have understood that I could be using ClassRegistry::init('Model'); to load a foreign model in my current model. But it doesn’t say much more on the syntax and how to actually use it afterwards. This is what I have tried, but nothing “is happening” when I am trying to print the array to see if it contains the right stuff. Basically I want to pull out the User data to use it in my validation.

class Booking extends AppModel {

    public $name = 'Booking';

    public $validate = array(
        'start_time' => array(
            'noOptionViolation' => array(
                'rule' => 'noOptionViolation',
                'allowEmpty' => false
            )
        ),
    );  

    public function noOptionViolation ($start_time) {

        $this->User = ClassRegistry::init('User');
        $allUsers = $this->User->find('all');
        print_r($allUsers);


    }

Is this correct syntax? Can I use all the methods of $this->User just like I would in a controller?

  • 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-14T16:59:46+00:00Added an answer on June 14, 2026 at 4:59 pm

    You can use import as detailed on this post:
    https://stackoverflow.com/a/13140816/1081396

    App::import('Model', 'SystemSettings.SystemSetting');
    $settings = new SystemSetting();
    $mySettings = $settings->getSettings();
    

    In your example it would be like:

    App::import('Model', 'Users.User');
    $user = new User();
    $allUsers = $user->find('all');
    print_r($allUsers);
    

    You could better use the import at the beginning of the model.

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

Sidebar

Related Questions

I have a custom class library that performs validation. I want to open up
I have a custom validation method that ensures an alarm can only be set
I'm creating custom UserControl in ASP.NET and I'm using System.ComponentModel.Attributes to decorate properties with
I have mastered creating custom data types and adding fields with CCK. Then I
I am creating custom membership provider for my asp.net application. I have also created
I'm looking for a tutorial that explains creating custom usercontrols in WPF. I want
I'm fairly new at creating custom unobtrusive validation, and am running into a weird
I'm currently creating some custom attributes for doing uploaded file validation. One of which
I am creating a custom property validation which should use the error string in
I am creating custom email validation attribute, my code : public class EmailAttribute :

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.