Instead of function showresult($yahoosearch = null)
use
function showresult(){
if(!empty($this->data) && isset($this->data['Yahoo']['yahoosearch]))
{
$yahoosearch = $this->data['Yahoo']['yahoosearch];
// do rest of searching code
} else {
// show input form
}
}
Basically anything POSTed to your controller will be in the $this-
>data array if you use the standard helper functions to create the
input fields.
Geoff
--
http://lemoncake.wordpress.com
On Sep 25, 6:52 am, seacloud9 <[EMAIL PROTECTED]> wrote:
> Issues with $html->input
>
> I am trying to pass a variable from the view (index) to the view
> (show) using the controller Yahoo. I have only been successful with
> this when I put the search content in the url.
> Examplehttp://ihang10.com/yahoo/show/testorhttp://ihang10.com/yahoo/show/cakephp
> I am new to cakePHP and I have not been able to find a way to pass the
> variable trough an input box. I know I am close I just can't seem to
> complete this problem. It could be that I am using the wrong helper.
> Your advice on this issue would be greatly appreciated. STUCK..
> Not working:http://ihang10.com/yahoo ?
>
> Here is the code for the working version (that does not have an input
> box....)
> <!---------------------------------------------
> Model Yahoo:
>
> <?php
> // app/models/yahoo.php
> vendor('zend_loader_yahoo');
>
> class Yahoo extends AppModel
> {
> var $useTable = false;
>
> function __construct()
> {
> ZendLoader::load('Service/Yahoo');
> }
>
> function getResultsby($yahoosearch)
> {
> $result = array();
>
> if (!empty($yahoosearch))
> {
> $yahoo = new
> Zend_Service_Yahoo("9Jd3X77V34H7qkFUr4RPUBOe5Uw77BnFogvFtRymuyW7pWMxwcadkV.Ag4QwluKU7tu9Hwo-");
> $result = $yahoo->webSearch($yahoosearch);
>
> }
>
> return $result;
> }}
>
> ?>
>
> Controller Yahoo_Controller
>
> <?php
> // app/controllers/yahoo_controller.php
>
> class YahooController extends AppController
> {
>
> var $helpers = array('Html', 'Ajax');
> var $layout = 'yahoo';
>
> function index()
> {
> }
>
> function showresult($yahoosearch = null)
> {
> $this->set('question', $this->showresult($yahoosearch));
> $yahoo = new
> Zend_Service_Yahoo("9Jd3X77V34H7qkFUr4RPUBOe5Uw77BnFogvFtRymuyW7pWMxwcadkV.Ag4QwluKU7tu9Hwo-");
> $result = $yahoo->webSearch('$question');
> return $result;
> $this->log('Something broke');
> }
>
> function show($yahoosearch = null)
> {
> $this->set('question', $this->Yahoo->getResultsby($yahoosearch));
> }
>
> }
>
> ?>
>
> View Show:
>
> <?php
> // app/views/yahoo/show.thtml
> foreach ($question as $answer)
> {
> echo "<h3><a href='{$answer->ClickUrl}'>{$answer->Title}</a></h3>";
> echo "{$answer->Summary}
> [<a href='{$answer->CacheUrl}'>Cached Version</a>]";}
>
> ?>
>
> This is the AJAX version that I just can't seem to make work:
>
> View: Index
>
> <?=$ajax->form(array('action'=>'/yahoo/showresult'), 'post',
> array('update'=>'yahoosearch','loading'=>"Toggle.display('spinner');",'complete'=>"Toggle.display('spinner');stripe();"))?
>
> <?=$html->image('spinner.gif', array('alt'=>'spinner',
> 'id'=>'spinner', 'style'=>'display:none;'))?>
> <fieldset>
> <label for="showresult">Search:</label>
> <?=$html->input('Yahoo/yahoosearch',array('type' => 'text', 'size'
> => '25'))?>
> <?=$html->submit('Find')?>
> </fieldset>
> <div id="yahoosearch"></div>
> </form>
>
> View: ShowResult
>
> <?php
> // app/views/yahoo/show.thtml
> foreach ($question as $result)
> {
> echo "<h3><a href='{$result->ClickUrl}'>{$result->Title}</a></h3>";
> echo "{$result->Summary}
> [<a href='{$result->CacheUrl}'>Cached Version</a>]";}
>
> ?>
>
> Yahoo_Controller:
>
> <?php
> // app/controllers/yahoo_controller.php
>
> class YahooController extends AppController
> {
>
> var $helpers = array('Html', 'Ajax');
> var $layout = 'yahoo';
>
> function index()
> {
> }
>
> function showresult($yahoosearch = null)
> {
> $this->set('question', $this->showresult($yahoosearch));
> $yahoo = new
> Zend_Service_Yahoo("9Jd3X77V34H7qkFUr4RPUBOe5Uw77BnFogvFtRymuyW7pWMxwcadkV.Ag4QwluKU7tu9Hwo-");
> $result = $yahoo->webSearch('$question');
> return $result;
> $this->log('Something broke');
> }
>
> function show($yahoosearch = null)
> {
> $this->set('question', $this->Yahoo->getResultsby($yahoosearch));
> }
>
> }
>
> ?>
>
> I belive it is really close but as I said I am having trouble passing
> the variable and I am not sure if I am using the correct helper. Your
> advice and input would be greatly appreciated. Thank You.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---