Welcome Guest, Not a member yet? Register   Sign In
rendering views question
#1

[eluser]matches[/eluser]
Sorry for the basic question.

How can I get the following controllers view to show in the productSearch view at the bottom of this post. Currently it just shows the productResults but not embedded in the productSearch view.

Thanks for the help.

ProductResults Controller
Code:
<?php
class ProductResults extends Controller
{
     function ProductResults()
     {
         parent::Controller();
         $this->load->helper('url');
         $this->load->helper('form');
     }
    
     public function showProducts()
     {
         $searchText = $_REQUEST['searchText'];
         $products = array();
         $oXML = simplexml_load_file('http://sandbox.api.shopping.com/publisher/3.0/rest/GeneralSearch?apiKey=authorized-key&trackingId=7000610&keyword;=' . $searchText);
        foreach ($oXML->categories->category->items->product as $oProduct)
        {
            
            echo "<img >images->image->sourceURL . "' />";
            echo '<h2>' . $oProduct->name . '</h2>';
            echo '<p>' . $oProduct->fullDescription . '</p>';
            echo sprintf('<a href="%s" title="%s">%s</a>',
                $oProduct->productOffersURL,
                $oProduct->name,
                'More information'
            );
        }
     }
}
?&gt;

ProductSearch Controller
Code:
&lt;?php

class ProductSearch extends Controller
{
     function ProductSearch()
     {
         parent::Controller();
         $this->load->helper('url');
         $this->load->helper('form');
     }
    
     function index()
     {
         $this->load->view('productSearch/index');
        
     }
    
    
}
?&gt;

Product Search View
Code:
&lt;html&gt;
    &lt;head&gt;
    &lt;/head&gt;
    &lt;body&gt;
        &lt;?=form_open('ProductResults/showProducts');?&gt;
            &lt;input type="text" name="searchText" /&gt;
            &lt;input type="submit" name="submit" /&gt;
        &lt;/form&gt;
        &lt;?php $this->load->view('productResults/index'); ?&gt;
    &lt;/body&gt;
&lt;/html&gt;
#2

[eluser]matches[/eluser]
OK, I was able to get it working like below. I have my showProducts function in my index function. But that can't be right, it looks awful.

Thanks again for any help.

Controller
Code:
&lt;?php
/*
* Created on Dec 3, 2008
*
* To change the template for this generated file go to
* Window - Preferences - PHPeclipse - PHP - Code Templates
*/

class ProductSearch extends Controller
{
     function ProductSearch()
     {
         parent::Controller();
         $this->load->helper('url');
         $this->load->helper('form');
     }
    
     function index()
     {
         function showProducts()
         {
             $searchText = $_REQUEST['searchText'];
             $products = array();
             $counter = 0;
             $oXML = simplexml_load_file('http://publisher.api.shopping.com/publisher/3.0/rest/GeneralSearch?apiKey=d033326f-fe2a-410b-87e3-e213ff3f462e&trackingId=7001224&keyword;=' . $searchText);
            foreach ($oXML->categories->category->items->product as $oProduct)
            {
                $counter++;
                
                /*echo "<img >images->image->sourceURL . "' />";
                echo '<h2>' . $oProduct->name . '</h2>';
                echo '<p>' . $oProduct->fullDescription . '</p>';
                echo sprintf('<a href="%s" title="%s">%s</a>',
                    $oProduct->productOffersURL,
                    $oProduct->name,
                    'More information'
                );*/
                $products[$counter] = "<img >images->image->sourceURL . "' />" .
                '<h2>' . $oProduct->name . '</h2>' .
                '<p>' . $oProduct->fullDescription . '</p>';    
                        
            }
            return $products;
         }
        
         $searchText = $_REQUEST['searchText'];
         if ($searchText)
         {
             $data['products'] = showProducts($searchText);
             $this->load->view('productSearch/index', $data);
         }
         else
         {
             $this->load->view('productSearch/index');
         }
      
        
        
     }    
    
}
?&gt;

View
Code:
&lt;html&gt;
    &lt;head&gt;
    &lt;/head&gt;
    &lt;body&gt;
        &lt;?=form_open('ProductSearch/index');?&gt;
            &lt;input type="text" name="searchText" /&gt;
            &lt;input type="submit" name="submit" /&gt;
        &lt;/form&gt;
        &lt;?php foreach($products as $product): ?&gt;
        &lt;?= $product ?&gt;
        &lt;?php endforeach; ?&gt;
    &lt;/body&gt;
&lt;/html&gt;
#3

[eluser]sl3dg3hamm3r[/eluser]
IMHO you shouldn't produce any html-tags at all in your controller (img, h2, p). I would remove it completely.
#4

[eluser]matches[/eluser]
I guess I'm sure how to avoid that.

Any advise on how to get that function out of the index function?




Theme © iAndrew 2016 - Forum software by © MyBB