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

  • Home
  • SEARCH
  • 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 999515
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:21:59+00:00 2026-05-16T07:21:59+00:00

In the modules actions, what is the best way to select records based on

  • 0

In the modules actions, what is the best way to select records based on an index other than the primary key id?

$this->city = Doctrine::getTable('City')->find(array($request->getParameter('city')));

This always returns a query with WHERE City.id= instead of WHERE City.city=

Do I have to do something like

$q = Doctrine_Query::create()
    ->from('City j')
    ->where('j.city = ?', $request->getParameter('city'));
    $this->city=$q->execute();
  • 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-16T07:22:00+00:00Added an answer on May 16, 2026 at 7:22 am

    find() method only finds a record by a primary key.

    You are able to find records by other fields with findBy*/findOneBy* methods just like @phidah mentioned (so it’s findOneByCity in your case).

    However, you shouldn’t use finder methods in your final code. From doctrine’s documenation:

    These are very limited magic finders and it is always recommended to expand your queries to be manually written DQL queries. These methods are meant for only quickly accessing single records, no relationships, and are good for prototyping code quickly.

    Read more about magic finders here: http://www.doctrine-project.org/documentation/manual/1_2/nl/dql-doctrine-query-language:magic-finders

    I’d rather put a short call to a model method in your action.

    Action:

    $this->city = CityTable::getByName($request->getParameter('city'));
    

    Model:

    public static function getByName($cityName)
    {
        return Doctrine_Core::getTable('City')
          ->createQuery('c')
          ->where('c.city = ?', $cityName)
          ->fetchOne();
    }
    

    As long as you give appropriate name to your method, which shows its intent, your code is far more readable.

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

Sidebar

Related Questions

I have the following structure: modules/group modules/group/modules/forum modules/group/modules/gallery modules/group/modules/events Is this a correct way
I created a page like this in one of my modules - /OrchardLocal/Module1/Controller1/Action1. It
Are there any prebuilt modules for this? Is there an event thats called everytime
What's the best way of appending an array of jQuery elements to the page?
I'm using the 'modules' front controller resource for the project setup. What's the best
How is the best way to load Category model, for ProductController in new, edit
Zend Framework/Doctrine 2 application.: /app /modules /blog /controllers /BlogController.php /domain /entities /services /PostService.php /repositories
how can I modify admin generated modules (acions and templates)? They are stored in
any time i write this: $this->setTemplate('module/action'); I'm getting this error: The template module/actionSuccess.php does
I want to know the difference between : $this->forward(module, action); And $this->redirect(module/action); My 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.