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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:34:30+00:00 2026-05-27T20:34:30+00:00

On my app a user may or may not have a profile. An example

  • 0

On my app a user may or may not have a profile. An example would be:

Array
(
    [User] => Array
        (
            [id] => 7
            [username] => noprofile
            [password] => 3b8cdb0c849f00f3634d9b29def1dac4e9235795
            [email] => noprofile@noprofile.com
            [status] => 0
            [code] => 114a10ebb6ffe364805aa70cd44bee7c
        )

    [Profile] => Array
        (
            [id] => 
            [firstname] => 
            [lastname] => 
            [gender] => 
            [dob] => 
            [user_id] => 
        )

)

Here the user noprofile has no matching content in the profiles table.

How do I show a 404 for when this happens? I’ve tried:

public function view ( $username )
{
    $this->Profile->User->recursive = 2;

    $profile = $this->Profile->User->find('first', array( 
                'conditions' => array('User.username' => $username) 
            ));

    if (empty($profile))
    {
        echo 'echo1';
        throw new NotFoundException('No profile');
    }
    else {
        echo 'echo2';
    }

    $this->set(compact('profile'));
}

But it doesn’t show the 404! I’m using CakePHP 2.0.

It’s because it finds the user so therefore profile is not empty! How do I check for the profile being empty then?

  • 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-27T20:34:31+00:00Added an answer on May 27, 2026 at 8:34 pm
    if (empty($profile['Profile']['id'])) {
        throw new NotFoundException();
    }
    

    I expect there are better ways to do it but that’s a quick fix. $profile, as you said, will not be empty as the user is found.

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

Sidebar

Related Questions

I have a winforms app that checks user credentials as it starts. If autharization
I'm building an app where the user may occasionally make a search. I'd like
The phrasing of the title may be a little confusing. I have an app
I have an application (cad like editor) in which the user may place a
I have a strange issue here with my Django app. I implemented the user
I would like to have an expandable/collapsible listview in my app, similar to how
I have a database with several tables, each one containing columns that may not
in a J2EE app if user explicitly takes out the the ending page name
I'm developing web app that user can save his/her work to server. The data
I wanted to wire the Google App Engine user service in Spring by first

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.