我想知道我的代码有什么问题: 这是我的控制器的功能:
public function testareAction(){
// $this->getResponse()->setHeader('Content-Type', 'application/json');
$this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender(true);
//$myarray = $_POST['data_post'];
//$product_ids = $_POST['product_ids'];
//$type = 1;
$model = new Application_Model_Order();
echo $model -> saveOrderNames();
}
这是我的模特中的函数:
public function saveOrderNames(){
return 1;
}
为什么我没有在浏览器中获得结果“1”?
我是新手所以请给我很好的指示。
public function indexAction()
{
if (!($locationUrl = $this->_getParam('locationUrl'))) {
throw new \Zend_Controller_Action_Exception('Location URL was not provided.', 404);
}
$this->maiDivClass = "block clear step1";
// get Location row
$mapper = new DbTable\Location();
$sql = $mapper->select()->where('url = ?', $locationUrl);
if (!($this->view->location = $mapper->fetchRowActive($sql))) {
throw new \Zend_Controller_Action_Exception('Location not found', 404);
}
// set active markup for location menu
$this->_helper->layout()->locationMainMenuUrl = $this->view->location->url;
// SEO
$this->setSeo(
$this->view->location->meta_title,
$this->view->location->meta_description,
$this->view->location->meta_keywords
);
// get day from param
$dayName = $this->_getParam('day', Cronos::getCurrentDayName());
$this->view->dayNo = Cronos::getWeekDayNumber($dayName);
if ($this->view->dayNo === false) {
throw new \Zend_Controller_Action_Exception('Invalid weekday provided.', 404);
}
$this->view->selectedDate = Cronos::getDateWithOffset($this->view->dayNo); // get date offset
$this->view->categMapper = new DbTable\Categories();
$appCfg = new Zend_Config_Ini(APPLICATION_PATH . '/configs/application.ini', APPLICATION_ENV);
$this->view->s3 = "http://".$appCfg->custom->s3->bucket;
$imgMapper = new Application_Model_Mapper_Images();
$this->view->imgs = $imgMapper->fetchAllByLocationId($this->view->location->id);
/**
* Show products only for allowed admin emails. Testing only.
* Admin must be logged in to see products, while the test is on.
*
* To disable, change custom.test.isEnabled flag in app.ini.
*/
$testCfg = Zend_Registry::get('Zend_Config')->custom->test->toArray();
$isEnabled = (bool) $testCfg['isEnabled'];
// test is enabled?
if ($isEnabled) {
$email = false;
$auth = Zend_Auth::getInstance();
// grab email, if logged in
if ($auth->hasIdentity()) { $email = $auth->getIdentity()->email; }
// has email? check it against config, else don't show products
$showProducts = ($email) ? in_array($email, (array) $testCfg['email']) : false;
// test is disabled: always show products
} else {
$showProducts = true;
}
if ($showProducts) {
// get categories & products for this date and location
$prodService = new \Application\Service\Products();
$this->view->categsWithProds = $prodService->getProducts($this->view->location->id, $this->view->selectedDate);
//check days of the week with products
$week = array();
$currentDay = Cronos::getWeekDayNumberByDate();
if($this->view->location->erp_name != "city lbox") {
for($day=$currentDay;$day<7;$day++)
{
$selectedDate = Cronos::getDateWithOffset($day);
$categswithprod = $prodService->getProducts($this->view->location->id, $selectedDate);
if(count($categswithprod))
$week[] = $day;
}
//we need to go to sunday and next week
for($day=0;$day<$currentDay;$day++)
{
$selectedDate = Cronos::getDateWithOffset($day);
$categswithprod = $prodService->getProducts($this->view->location->id, $selectedDate);
if(count($categswithprod))
$week[] = $day;
}
} else {
for($day = $currentDay; $day<7;$day++) {
$week[] = $day;
}
for($day = 0; $day<$currentDay; $day++) {
$week[] = $day;
}
}
$this->view->week = $week;
$specialMenuRows = $this->view->location->getSpecialMenus(new Zend_Date());
$this->view->specialMenus = $this->view->partial('_partials/specialMenu.phtml', array('specialMenus' => $specialMenuRows));
$this->view->categsWithProdsALaCarte = $prodService->getProducts($this->view->location->id, $this->view->selectedDate, 1);
// no xml; show "Download PDF"
} else {
$this->setPdfLink();
$this->renderScript('location/no_xml.phtml');
}
}
好的,我在models文件夹中创建了这个文件:OrderNames.php 这就是我的模型所包含的内容:
<?php
class OrderNames {
public function saveOrderNames(){
return 1;
}
}
?>
这是控制器的功能:
public function testareAction(){
$this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender(true);
echo "1tralala";
$model = new Application_Model_OrderNames();
echo "2<hr>";
$model -> saveOrderNames();
}
为什么字符串“2tralala”没有出现?
答案 0 :(得分:0)
您致电:$model = new Application_Model_OrderNames();
php文件的名称是OrderNames.php
而班级是
class OrderNames {
public function saveOrderNames(){
return 1;
}
}
所以尝试替换类的名称:
class Application_Model_OrderNames {...