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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T10:14:19+00:00 2026-05-18T10:14:19+00:00

My problem right now is that a Model has a set of Validation rules

  • 0

My problem right now is that a Model has a set of Validation rules like so:

var $validate = array(
    'title' => array(
        'rule' => 'notEmpty'
    ),
    'uri' => array(
        'slugged' => array(
            'rule' => '/^[a-z0-9-_]+$/i',
            'message' => 'This field should only contain characters, numbers, dashes and underscores'
        ),
        'uniqueUrl' => array(
            'rule' => array('uniqueUrl'),
            'message' => 'A page has already acquired this url'
        )
    ),
    'meta_keywords' => array(
        'rule' => 'notEmpty'
    ),
    'meta_description' => array(
        'rule' => 'notEmpty'
    ),
    'layout' => array(
        'rule' => 'notEmpty'
    )
);

The problem is that in another model that has hasOne relationship its controller also inserts data into it. I want to NOT require the title, uri and layout from that page. How do I do it?

I have a Post Model and I set Page values from there.

Array
(
    [Post] => Array
        (
            [title] => data[Post][title]
            [body] => 

Post Body

        )

    [Category] => Array
        (
            [Category] => Array
                (
                    [0] => 1
                    [1] => 2
                    [2] => 3
                    [3] => 4
                )

        )

    [Page] => Array
        (
            [meta_keywords] => data[Page][meta_keywords]
            [meta_description] => data[Page][meta_description]
        )

)

I do this from the controller to set info for the Page model

$this->data['Page']['title'] = $this->data['Post']['title'];

It turns to be like this:

Array
(
    [Post] => Array
        (
            [title] => data[Post][title]
            [body] => 

Post Body

        )

    [Category] => Array
        (
            [Category] => Array
                (
                    [0] => 1
                    [1] => 2
                    [2] => 3
                    [3] => 4
                )

        )

    [Page] => Array
        (
            [meta_keywords] => data[Page][meta_keywords]
            [meta_description] => data[Page][meta_description]
            [title] => data[Post][title]
        )

)

My problem is that I do not require a Page field when saving. Post belongsTo Page.

I don’t require [Page][layout] when saving a Post as a Post uses the default view of the method in the Post Controller. A page uses static pages and require them when creating a Page, not when creating a Post.

  • 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-05-18T10:14:19+00:00Added an answer on May 18, 2026 at 10:14 am

    You’re preprocessing the data before it goes for validation, so you’re taking some control away from validation. As you seem to be making the decision (in code) whether or not certain fields need to be artificially populated you are rendering those parts of the validation redundant and you should remove them. If you have multiple validations in php, you’re going to end up confused.

    Where to do this or how to do it more cleanly? WellbeforeValidate might be the ‘correct’ place to do this, but I would do it wherever it best fits with the logic of your application. Function should come before elegance.

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

Sidebar

Related Questions

No related questions found

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.