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

The Archive Base Latest Questions

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

**i build dvd script for dvds library.. when i want to edit dvds details

  • 0

**i build dvd script for dvds library.. when i want to edit dvds details the image i have uploded dont display but when i see databse table i see it is already into this table and i find the image in the webroot img folder (dvds)..so how to show image to edit it?

Dvds Controller

    <?php


class DvdsController extends AppController {
    // good practice to include the name variable
    var $name = 'Dvds';

    // load any helpers used in the views
    var $helpers = array('Html', 'Form', 'Javascript', 'Misc');

    // global ratings variable
    var $ratings = array('0'=>'0', '1'=>'1', '2'=>'2', '3'=>'3', '4'=>'4', '5'=>'5', '6'=>'6', '7'=>'7', '8'=>'8', '9'=>'9', '10'=>'10');

    /**
     * index()
     * main index page for dvds
     * url: /dvds/index
     */
    function index() {
        // get all dvds from database where status = 1
        //$dvds = $this->Dvd->find("Dvd.status=1", null, "Dvd.name");
     $dvds = $this->Dvd->find('all', array('conditions' => array('Dvd.status' => '1')));
        // save the dvds in a variable for the view
        $this->set('dvds', $dvds);
    }

    /**
     * view()
     * displays a single dvd and all related info
     * url: /dvds/view/dvd_slug
     */
    function view($slug) {
        // if slug is null
        if(!$slug) {
            // set a flash message
            $this->Session->setFlash('Invalid slug for DVD', 'flash_bad');
            // redirect user
            $this->redirect(array('action'=>'index'));
        }

        // find dvd in database
        $dvd = $this->Dvd->findBySlug($slug);

        // if dvd has been found
        if(!empty($dvd)) {
            // set the dvd for the view
            $this->set('dvd', $dvd);
        } else {
            // set a flash message
            $this->Session->setFlash('Invalid slug for DVD', 'flash_bad');
            // redirect user
            $this->redirect(array('action'=>'index'));
        }
    }

    /**
     * admin_index()
     * main index page for admin users
     * url: /admin/dvds/index
     */
    function admin_index() {
        // get all dvds from database where status = 1, order by dvd name
       //   $dvds = $this->Dvd->findAll("Dvd.status=1", null, "Dvd.name");
        $dvds = $this->Dvd->find('all', array('conditions' => array('Dvd.status' => '1')));

        // save the dvds in a variable for the view
        $this->set('dvds', $dvds);
    }

    /**
     * admin_add()
     * allows an admin to add a dvd
     * url: /admin/dvds/add
     */
    function admin_add() {
        // if the form data is not empty
        if (!empty($this->data)) {
            // check for image
            $image_ok = $this->_upload_image();

            // if the image was uploaded successfully
            if($image_ok) {
                // initialise the Dvd model
                $this->Dvd->create();

                // create the slug
                $this->data['Dvd']['slug'] = $this->slug($this->data['Dvd']['name']);

                // check for a dvd with the same slug
                $dvd = $this->Dvd->find('first', array(
                    'conditions' => array(
                        'Dvd.slug'=>$this->data['Dvd']['slug'],
                        'Dvd.status' => '1'
                    )
                ));

                // if slug is not taken
                if(empty($dvd)) {
                    // try saving the dvd
                    if ($this->Dvd->save($this->data)) {
                        // set a flash message
                        $this->Session->setFlash('The DVD has been saved', 'flash_good');

                        // redirect
                        $this->redirect(array('action'=>'index'));
                    } else {
                        // set a flash message
                        $this->Session->setFlash('The DVD could not be saved. Please, try again.', 'flash_bad');
                    }
                } else {
                    // set a flash message
                    $this->Session->setFlash('The DVD could not be saved. The Name has already been taken.', 'flash_bad');
                }
            }
        }

        // find dvd options in a list format
        // new 1.2 feature, can also have 'count' and 'first'
        $formats    = $this->Dvd->Format->find('list');
        $types      = $this->Dvd->Type->find('list');
        $locations  = $this->Dvd->Location->find('list');
        $ratings    = $this->ratings;

        // set the variables so they can be accessed from the view
        $this->set(compact('formats', 'types', 'locations', 'ratings'));
    }

    /**
     * admin_edit()
     * allows an admin to edit a dvd
     * url: /admin/dvds/edit/id
     */
    function admin_edit($id = null) {
        // if the id is null and the form data empty
        if (!$id && empty($this->data)) {
            // set a flash message
            $this->Session->setFlash('Invalid Dvd', 'flash_bad');
            // redirect the admin
            $this->redirect(array('action'=>'index'));
        }

        // if the form was submitted
        if (!empty($this->data)) {
            // check for image
            $image_ok = $this->_upload_image();

            // if the image was uploaded successfully
            if($image_ok) {
                // create the slug
                $this->data['Dvd']['slug'] = $this->slug($this->data['Dvd']['name']);

                // check for a dvd with the same slug
                $dvd = $this->Dvd->find('first', array(
                    'conditions' => array(
                        'Dvd.slug'=>$this->data['Dvd']['slug'],
                        'Dvd.status' => '1'
                    )
                ));

                // if slug is not taken
                if(empty($dvd) || $dvd['Dvd']['id'] == $id) {
                    // try to save the Dvd
                    if ($this->Dvd->save($this->data)) {
                        // set a flash message
                        $this->Session->setFlash('The Dvd has been saved', 'flash_good');
                        // redirect the admin
                        $this->redirect(array('action'=>'index'));
                    } else {
                        // set a flash message
                        $this->Session->setFlash('The Dvd could not be saved. Please, try again.', 'flash_bad');
                    }
                } else {
                    // set a flash message
                    $this->Session->setFlash('The DVD could not be saved. The Name has already been taken.', 'flash_bad');
                }
            }
        } else {
            // find the DVD from the database and save it in the data array
            $this->data = $this->Dvd->read(null, $id);
        }

        // find dvd options from database in a list
        $formats    = $this->Dvd->Format->find('list');
        $types      = $this->Dvd->Type->find('list');
        $locations  = $this->Dvd->Location->find('list');
        $ratings    = $this->ratings;
        $this->set(compact('formats','types','locations', 'ratings'));
    }

    /**
     * admin_delete()
     * allows an admin to delete a dvd
     * url: /admin/dvds/delete/1
     */
    function admin_delete($id = null) {
        // if the id is null
        if (!$id) {
            // set flash message
            $this->Session->setFlash('Invalid id for Dvd', 'flash_bad');
            // redirect
            $this->redirect(array('action'=>'index'));
        }

        // set the id of the dvd
        $this->Dvd->id = $id;

        // try to change status from 1 to 0
        if ($this->Dvd->saveField('status', 0)) {
            // set flash message
            $this->Session->setFlash('The Dvd was successfully deleted.', 'flash_good');
        } else {
            // set flash message
            $this->Session->setFlash('The Dvd could not be deleted. Please try again.', 'flash_bad');
        }

        // redirect
        $this->redirect(array('action'=>'index'));
    }

    /**
     * upload_image()
     * private function to upload a file if it exists in the form
     */
    function _upload_image() {
        // init
        $image_ok = TRUE;

        // if a file has been added
        if($this->data['File']['image']['error'] != 4) {
            // try to upload the file
    $result = $this->upload_files('img/dvds', $this->data['File']);

            // if there are errors
            if(array_key_exists('errors', $result)) {
                // set image ok to false
                $image_ok = FALSE;
                // set the error for the view
                $this->set('errors', $result['errors']);
            } else {
                // save the url
                $this->data['Dvd']['image'] = $result['urls'][0];
            }
        }

    return $image_ok;
    }
}

?>

and the view file is

<div class="dvds form">

<?php
// if there was an error uploading the file then display errors here
if(isset($errors)) {
    echo $misc->display_errors($errors);
}
?>

<?php echo $form->create('Dvd', array('type'=>'file'));?>
    <fieldset>
        <legend>Edit a Dvd</legend>
        <?php
        // create the form inputs

        // include the id of the DVD as a form input
        // CakePHP will automatically create this as a hidden element
        echo $form->input('id');
        echo $form->input('name', array('label'=>'Name: *'));
        echo $form->input('format_id', array('label'=>'Format: *', 'type'=>'select', 'options'=>$formats));
        echo $form->input('type_id', array('label'=>'Type: *', 'class'=>'type_select'));
        echo $form->input('location_id', array('label'=>'Location: *'));

        // display image if it exists
        if(!empty($this->data['Dvd']['image'])): ?>
        <div class="input">
            <label>Current Image:</label>
<img src="/<?php echo $this->data['Dvd']['image']; ?>" width="100" />
        </div>
        <?php endif;

        echo $form->input('File.image', array('label'=>'Image:', 'type'=>'file'));
        echo $form->input('rating', array('label'=>'Rating:'));
        echo $form->input('website', array('label'=>'Website URL:'));
        echo $form->input('imdb', array('label'=>'Imdb URL:'));
        echo $form->input('discs', array('label'=>'Number of Discs:', 'class'=>'tv_hide'));
        echo $form->input('episodes', array('label'=>'Number of Episodes:', 'class'=>'tv_hide'));
        ?>
    </fieldset>
<?php echo $form->end('Save');?>
</div>

<ul class="actions">
    <li><?php echo $html->link('List DVDs', array('action'=>'index'));?></li>
    <li><?php echo $html->link('Add a DVD', array('action'=>'add'));?></li>
</ul>
  • 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-26T13:27:30+00:00Added an answer on May 26, 2026 at 1:27 pm
       <img src="/<?php echo $this->data['Dvd']['image']; ?>" width="100" />
    

    produces:

    <img src="/img/dvds/Blue_hills.jpg" width="100" />

    as your comment suggests, the actual src should be:

    <img src="/dvdcatalog/img/dvds/Blue_hills.jpg" width="100" />

    or even

    <img src="http://localhost/dvdcatalog/img/dvds/Blue_hills.jpg" width="100" />

    Use the image helper which uses the correct webroot path for outputting links etc

     if(!empty($this->data['Dvd']['image'])): ?>
        <div class="input">
         <label>Current Image:</label>
         <?php 
           echo $this->Html->image($this->data['Dvd']['image'], array('width'=>100));
         ?>
        </div>
      <?php endif; 
    

    and you should get the desired result.

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

Sidebar

Related Questions

my build keeps on failing, in the configuration under build script i have: if
I build a script that combines all css on a page together to use
I have managed to build an index in Solr which I can search on
I am trying to build a dictionary with two keys but am getting a
I know how to build a .NET bootstrapper to be distributed via CD/DVD using
i build an app to send OSC-Messages through WLAN. Thats why i have a
The build error I am getting is: ld: library not found for -lAdServer_Iphone I
I build applications using C++, C# and Java. But when I try to copy
I have content to be installed, but it's file and folder layout is determined
I have few builds defined in the TFS project and I want to trigger

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.