hi all,
i'm new to cake, using v1.1.x. i have a search on the main page of my
app that searches within 'conditions', 'remedies' & (eventually)
'ratings'. i have models/controllers set up for 'conditions',
'remedies', 'ratings' & 'search'. the 'search' has useTable = False.
the table associations are:
'conditions' hasMany 'remedies'
'remedies' belongsTo 'conditions'
'remedies' hasMany 'ratings'
'ratings' belongsTo 'remedies'
i'm using AD7six's pagination and 'dbsearch' helper to return results
for my searches. the problem i'm running into (i think) is that the
search result is built after the pagination is initialized. i've tried
to find a way to pass the pagination the values after the fact, but it
won't let me do it or i can't figure out how to do it. so, it seems to
bomb in the code where the pagination looks for 'total' and if 'total'
is not set, it's calling findCount for the controller, and it bombs
because there is no table associated with that controller. (i'm
guessing)
any help would be greatly appreciated...thanks in advance!
here's that code that is failing in my case:
[pagination.php]
if (isset($this->total))
{
$count = $this->total;
}
else
{
$count = $this->controller->{$this->modelClass}->findCount($criteria,
0);
}
here is my search_controller:
<?php
class SearchController extends AppController {
var $name = 'Search';
var $helpers = array('Pagination');
var $components = array ('Pagination');
var $uses = array('Condition');
function index() {
vendor('search'.DS.'DatabaseSearch');
$this->db =& ConnectionManager::getDataSource('default');
$config = $this->db->config;
// settings: host, database, login, password, debug -- if debug is
true, it will show the sql query from the search.
/*$this->set('DBSearch', new
DatabaseSearch('localhost','oscommerce','root','',false));*/
$this->set('DBSearch', new DatabaseSearch($config['host'],
$config['database'],$config['login'],$config['password'],false));
$criteria=NULL;
list($order,$limit,$page) = $this->Pagination->init($criteria, null,
array('total'=>'10'));
}
}
?>
and, here is the search index.thtml:
<h1>Search Results</h1>
<?php
$pagination->setPaging($paging); // Initialize the pagination
variables
if (isset($_POST["DatabaseSearchNeedle"]))
{
$query = $DBSearch->needle;
echo '<div style="clear: both;"><!-- results --></div>';
//search in table articles, return id, search in listed columns, text
and logical operators
$search_result = $DBSearch-
>DoSearch("conditions","id",array("name","description"),"","");
//search in table articles, return headline, search in listed columns,
text and logical operators
$search_result_title = $DBSearch-
>DoSearch("conditions","name",array("name","description"),"","");
// Make a MySQL Connection
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("myremedyfind") or die(mysql_error());
echo "<br />";
echo '<p>';
$i = 0;
if ($search_result) {
foreach ($search_result as $result) {
// Retrieve all the data from the "example" table
$nameresult = mysql_query("SELECT * from conditions where id =
$result")
or die(mysql_error());
// store the record of the "example" table into $row
$row = mysql_fetch_array( $nameresult );
// Print out the contents of the entry
echo '<a href="'.$html->url('/conditions/view/').$result.'"
title="view">';
/*echo $search_result_title[$i]; */
echo $row['name'];
echo '</a><br />';
echo $row['description'];
echo '<br /><br /><br />';
$i++;
}
echo $this->renderElement('pagination'); // Render the pagination
element
}
else echo "No results.";
echo '</p>';
} ?>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---