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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T14:09:44+00:00 2026-06-08T14:09:44+00:00

I’m building my very first and simple app, but because I’m new to web-development

  • 0

I’m building my very first and simple app, but because I’m new to web-development I have some questions on how to properly organize my DB structure (and models).

One of my pages is an actor filmography so I need to display:

Year, director, description etc. And also I need to display a few pictures related to current film.

As far as I know I need to make 2 tables in my database.
First one with ID and all other fields (Year, director, description). And second table with film ID and some fields for images file names. It is a right way?

But I don’t understand how to link this tables together and when retrieve my data from this two tables and send it to the View. I read a cookbook but it’s not simple for a newbie.

Can someone please provide me an example related to my requirements?

  • 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-06-08T14:09:46+00:00Added an answer on June 8, 2026 at 2:09 pm

    You’re correct in assuming you’ll need 2 tables. For easiest configuration, follow Cake’s conventions. Tables are plural. We’ll also use the automatically updated created and modified fields. Your tables will look something like this (add extra columns as needed):

    actors

    id
    year
    director
    description
    created # automatically filled in by cake
    modified # automatically filled in by cake
    

    images

    id
    actor_id
    path
    created
    modified
    

    Now, update your models to reflect the relationships. You have Actor hasMany Image here, and Image belongsTo Actor.

    /app/Model/Actor.php

    <?php
    class Actor extends AppModel {
      public $hasMany = array('Image');
    }
    

    /app/Model/Image.php

    <?php
    class Image extends AppModel {
      public $belongsTo = array('Actor');
    }
    

    Since we’ve used Cake’s conventions, it will automatically know the table, foreign keys, and pull the relationships when you do a find().

    We’ll make a quick index action for your actors.

    /app/Controller/ActorsController.php

    <?php
    App::uses('AppController', 'Controller');
    class ActorsController extends AppController {
      public function index() {
        // get all actors and their images
        $this->Actor->recursive = 1;
        $actors = $this->Actor->find('all');
        // send to view as a variable named '$actors'
        $this->set('actors', $actors);
      }
    }
    

    In your view, iterate through the actors and display information as you like! Here’s an example of a very simple view that shows the actors name and first image in a table.

    /app/View/Actors/index.ctp

    <table>
      <thead>
        <tr>
          <th>Name</th>
          <th>Image</th>
        </tr>
      </thead>
      <tbody>
    <?php
    foreach ($actors as $actor) {
      $name = $this->Html->tag('td', $actor['Actor']['name']);
      // show first image
      $img = $this->Html->image($actor['Image'][0]['path']);
      $image = $this->Html->tag('td', $img);
      echo $this->Html->tag('tr', $name.$image);
    }
    ?>
      </tbody>
    </table>
    

    99% of this work can be done by using Cake’s bake shell. It will generate models, controllers, and views for you. Then you can go in and customize them as you like. I really recommend getting bake working as it will make your life easier and even provide you with best practices hints.

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

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
We're building an app, our first using Rails 3, and we're having to build
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I'm making a simple page using Google Maps API 3. My first. One marker
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but

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.