我對OOPS和Zend相當陌生。我將一部分Web應用程序代碼轉換爲Zend框架,我不能在這裏發佈所有代碼,因爲它相當長。我在下面的代碼中創建了一個模型(我只能發佈兩個函數),我想從控制器訪問函數內部的變量,然後在HTML表格中打印出來(我想我必須使用「視圖」認爲」,下面是我的模型:在Zend框架中從控制器訪問模型中聲明的函數中的變量
public function getVenueTypes()
{
$poiTypes = array();
if($this->_cache)
{
$key = $this->getCacheKey()."poiTypes_stats:{$this->language}";
}
if(!$poiTypes)
{
$sql = "SELECT poi_type_id, poi_type_name_".$this->language."
AS
poi_type_name
FROM
poi_types
ORDER BY
poi_type_name_".$this->language." ASC";
$result = mysql_query($sql);
if(!$result)
{
$message = 'Invalid query: ' . mysql_error() . "\n";
$message .= "Whole query: \n\n$sql\n";
die($message);
}
while($row = mysql_fetch_array($result))
{
$poiTypes[] = array('id' => $row['poi_type_id'] ,'name' => $row['poi_type_name']);
}
print_r($poiTypes);
if ($this->_cache)
{
$this->_cache->save($key, $poiTypes);
}
}
foreach($poiTypes as $poiType)
{
$count_type = null;
if($this->_cache)
{
$key = $this->getCacheKey()."poiTypeCount:{$poiType['id']}:{$this->metro_id}";
$count_type = $this->_cache->load($key);
}
if(!$count_type)
{
$sql = "SELECT COUNT(*) FROM
poi
WHERE
find_in_set('{$poiType['id']}', poi_type_id_array)
AND poi_status = 1 AND poi_address_prefecture_id = '$this->metro_id'";
$result = mysql_query($sql) or die(mysql_error());
}
if(!$result)
{
$message = 'Invalid query: ' . mysql_error() . "\n";
$message .= "Whole query: \n\n$sql\n";
die($message);
}
while($count = mysql_fetch_array($result))
{
$count_type[$poiType['id']][$this->metro_id] = $count['COUNT(*)'];
}
if($this->_cache)
{
$this->_cache->save($key, $count_type);
}
}
}
任何幫助表示高度讚賞,我希望我是不夠清楚,並在此先感謝
是的,我有基本的瞭解,所以可能是我不夠明確,我只是發佈一個功能,而不在模型和控制器類聲明,使之短。我如何從控制器訪問變量,如$ count_type [$ poiType ['id']] [$ this-> metro_id](來自上面的代碼)?如果我的問題不成熟,我很抱歉,我想學習OOPS和Zend。感謝您的回覆,希望能聽到更多。 – Uday