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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:39:19+00:00 2026-05-31T13:39:19+00:00

//My Owner Model var $belongsTo = array( ‘Owner’ => array( ‘className’ => ‘User’, ‘foreignKey’

  • 0
//My Owner Model
var $belongsTo = array(
    'Owner' => array(
        'className' => 'User',
        'foreignKey' => 'owner',
    ),
);

//My Tickets Controller

//Find the owners of the ticket to build select box
$owners = $this->Ticket->Owner->find('list', array(
         'fields' => array('Owner.id', 'Owner.username')
         'order' => array('Owner.username' => 'asc')
));

//Add "All" to the array of owners at 0 (no owner ids are 0)
array_splice($owners, 0, 0, "All");
//Set owner variable in my view.
$this->set(compact('owners'));

//My template file or view
echo $this->Form->create('Ticket', array(
    'url' => array_merge(array('action' => 'find'), $this->params['pass'])));
    echo $this->Form->input('title', array('div' => false));
    echo "<br /><br />";
            //Build the selectbox ordered by username
    echo $this->Form->input('owner', array('div' => false, 'options' => $owners, 'id' => 'EndUser'));
    echo "<br /><br />";
    echo $this->Form->submit(__('Search', true), array('div' => false));
    echo $this->Form->end();

When the select box is built the select box is sorted by username like I would like – but their ids do not switch with the username.

If I do a print_r($owners) before the array_splice($owners, 0, 0, "All"); the array is correct. When i print_r($owners) after the array_splice($owners, 0, 0, "All"); the array is incorrect – but I don’t know why… I am assuming array_splice renumbers the array… How could add “Any” to the array without messing up my relationships?

  • 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-31T13:39:20+00:00Added an answer on May 31, 2026 at 1:39 pm

    You’d best use the empty option of the input method of the Form helper. You can pass along a key to go with it, so change:

    echo $this->Form->input('owner', array('div' => false, 'options' => $owners, 'id' => 'EndUser'));
    

    To this:

    echo $this->Form->input('owner', array(
        'div' => false,
        'options' => $owners,
        'empty' => array(0 => 'All'), // Add this line
        'id' => 'EndUser'
    ));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given the following models: class Graph(models.Model): owner = models.ForeignKey(User) def __unicode__(self): return u'%d' %
I have something like this: class Video(models.Model): user = models.ForeignKey(User, related_name='owner') ... and I'm
I have a controller/model hypothetically named Pets. Pets has the following declarations: belongs_to :owner
I have a Website model, that has a @Required User owner property. This property
I have a model called Item , with m2m relation to User ("owner"). For
I have a basic FK to user, call it owner class Baz(models.Model): owner =
Given the Django models: class ContainerOwner(models.Model): id = models.IntegerField() class Container(models.Model): owner = models.ForeignKey(ContainerOwner)
I've got two models: class Solution < ActiveRecord::Base belongs_to :owner, :class_name => User, :foreign_key
Is there a way to reference a model's ManyToMany, Related, ForeignKey fields through a
@{ var grid = new WebGrid(Model.Auctions, rowsPerPage: Model.PagingInfo.ItemsPerPage, defaultSort: AddedDate); } @grid.GetHtml( columns: grid.Columns(

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.