0

I am new to Magento.

I have create one dummy page in Magento, when I display this page images are not showing.

But this code works in an .html file. Could you tell me where I went wrong?

public function indexAction()
    {
        echo '<html lang="en">';
        echo '<head>';
        echo '<title>Simplest jQuery Slideshow</title>';
        echo '<style type="text/css">
        .body
        {
            font-family: Arial, Helvetica, sans-serif;
            font-size: 12px;
        }

        .fadein
        {
            position: relative;
            height: 332px;
            width: 500px;
            margin: 0 auto;
            background: url("slideshow-bg.png") repeat-x scroll left top transparent;
            padding: 10px;
        }
        .fadein img
        {
            position: absolute;
            left: 10px;
            top: 10px;
        }
         </style>';
        echo '<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js" type="text/javascript"></script>';
        echo '<script type="text/javascript">';
        echo ' $(function () {';
        echo '$(\'.fadein img:gt(0)\').hide();';
        echo 'setInterval(function () { $(\'.fadein :first-child\').fadeOut().next(\'img\').fadeIn().end().appendTo(\'.fadein\'); }, 3000);
        });';
        echo '</script>';
        echo '</head>
        <body>
        <div class="fadein">';
        echo '<img src="C:/xampp/htdocs/magento/skin/frontend/test/default/images/media/1.jpg" >
        <img src="C:/xampp/htdocs/magento/skin/frontend/test/default/images/media/2.jpg" >
        <img src="C:/xampp/htdocs/magento/skin/frontend/test/default/images/media/3.jpg" >
        <img src="C:/xampp/htdocs/magento/skin/frontend/test/default/images/media/4.jpg" >
        <img src="C:/xampp/htdocs/magento/skin/frontend/test/default/images/media/5.jpg" >
         </div>
        </body>
        </html>';
    }

2 Answers 2

1

I'd advice you to move your HTML to a PHTML file using the layout XML. This blogpost should help you along with that.

For displaying images located in the skin folder please use $this->getSkinUrl('images/imagename.jpg');. This will dynamically set the right path.

1

Your actual problem:

I doubt that your image path should be a fully-qualified path on-disk. You image path should be relative to your domain.

A better way:

You should consider this being a CMS page. You can edit all of the source and upload images - it'll resolve the image path for you.

Additionally, as Sander points out, almost all of the content you're echo-ing should be in a template include (phtml) file. Echoing content in the manner you're doing is bound to be wrought with problems.

Off topic / Don't do this:

If you do insist on setting body content directly from a controller, at least do it with PHP heredoc and setBody:

    public function indexAction()
    {

$html = <<<HTML

    <html>
    <head>
        <title>My Sweet Stand-alone page</title>
    </head>
    <body>
        <h1>I AM TEH AWSUM!</h1>
    </body>
    </html>


HTML;


    $this->getResponse()->setBody($html);

    }

Beware, the lack of indentation in the heredoc syntax is meaningful.

Even though I know you probably will - please, please, please, don't do this.


Read more about heredoc over here, doc:

http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.