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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T13:26:22+00:00 2026-05-29T13:26:22+00:00

I have this application that directs users to Types of attractions with this function:

  • 0

I have this application that directs users to Types of attractions with this function:

public function index($type=null) {
        $this->set('title','What to do when you visit Gulf Shores');

        $this->paginate['Attraction']=array(
                'limit'=>9,
                'order'=>array('Attraction.id'=>'asc'),
                'conditions'=>array(
                        'active'=>1,
                        'attr_type'=>$type
                        )
                );
        $c=$this->paginate('Attraction');
        $this->set('attractions', $c);

}

and it works great, but I’d like users to also be able to go to a front page /attractions/ that doesn’t filter out by attr_type. This function shows zero results (as obviously $type still = null) for the front page. Is there a step I’m missing or must I have a view.ctp file and function in my 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-05-29T13:26:23+00:00Added an answer on May 29, 2026 at 1:26 pm

    You could use an if statement to determine the conditions:

    public function index($type = null) {
        $this->set('title', 'What to do when you visit Gulf Shores');
    
        $conditions = array();  //create $conditions outside of the if statement
        if ($type) {    //if $type is equal to anything other than null or 0
            $conditions = array(
                'active' => 1,
                'attr_type' => $type
            );
        } else {
            $conditions = array(
                'active' => 1
            );
        }
    
        $this->paginate['Attraction'] = array(
            'limit' => 9,
            'order' => array('Attraction.id' => 'asc'),
            'conditions' => $conditions
        );
        $c = $this->paginate('Attraction');
        $this->set('attractions', $c);
    }
    

    It’s not actually necessary to create $conditions outside of the if statement in PHP but it is in a lot of other programming languages because of scope.

    If you create a variable inside a if statement is it available outside the if statement?

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

Sidebar

Related Questions

I have this application that need to do some things in protected paths (like
I have this application that will recurse all folders in a given directory and
I have this web application that has grown to an unmanageable mess. I want
So I have this c# application that needs to ping my web server thats
I have an existing application that is written in C++ for Windows. This application
I have an C# form application that use an access database. This application works
I have a VB6's Application that is in production environment right now, this application
I have this senario. We have an application server that contains a few web
I have this code inside a class that is used by an application and
I have an application that has a UITableView. This UITableView is populated by an

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.