0

我想初始化一个类,但我得到一个错误 324 (net::ERR_EMPTY_RESPONSE)

这是我要初始化的类:

<?php
class CMS_Content_Item_Page extends CMS_Content_Item_Abstract
{
public $id;
public $name;
public $headline;
public $image;
public $description;
public $content;
}

这是它扩展的类:

<?php
abstract class CMS_Content_Item_Abstract
{
const NO_SETTER = 'Setter methode bestaat niet';
public $id;
public $name;
public $parent_id = 0;
protected $_namespace = 'page';
protected $_pageModel;

public function __construct($pageId = null)
{
    $this->_pageModel = new CMS_Content_Item_Page();
    if(null != $pageId)
    {
        $this->loadPageObject(intval($pageId));
    }
}

protected function _getInnerRow($id = null)
{
    if($id == null)
    {
        $id = $this->id;
    }
    return $this->_pageModel->find($id)->current();
}

protected function _getProperties()
{
    $propertyArray = array();
    $class = new Zend_Reflection_Class($this);
    $properties = $class->getProperties();
    foreach($properties as $property)
    {
        if($property->isPublic())
        {
            $propertyArray[] = $property->getName();
        }
    }
    return $propertyArray;
}

protected function _callSetterMethod($property,$data)
{
    $method = Zend_Filter::filterStatic($property, 'Word_UnderscoreToCamelCase');
    $methodName = '_set' . $method;
    if(method_exists($this,$methodName))
    {
        return $this->$methodName($data);           
    }   
    else
    {
        return self::NO_SETTER; 
    }
}

public function loadPageObject($id)
{
    $this->id = $id;
    $row = $this->getInnerRow();
    if($row)
    {
        if($row->namespace != $this->_namespace)
        {
            throw new Zend_Exception('Niet in staat om pagina type te weergeven:' 
            . $row->namespace . ' naar type:' . $this->_namespace);
        }
        $this->name = $row->name;
        $this->parent_id = $row->parent_id;
        $contentNode = new Model_ContentNode();
        $nodes = $row->findDependentRowset($contentNode);
        if($nodes)
        {
            $properties = $this->_getProperties();
            foreach($nodes as $node)
            {
                $key = $node['node'];
                if(in_array($key,$properties))
                {
                    $value = $this->_callSetterMethod($key,$nodes);
                    if($value === self::NO_SETTER)
                    {
                        $value = $node['content'];
                    }
                    $this->$key = $value;
                }
            }
        }
    }
    else
    {
        throw new Zend_Exception("Niet in staat om content item te laden");
    }
}

public function toArray()
{
    $properties = $this->_getProperties();
    foreach($properties as $property)
    {
        $array[$property] = $this->$property;
    }
    return $array;
}

public function save()
{
    if(isset($this->id))
    {
        $this->_update();
    }
    else
    {
        $this->_insert();
    }
}

protected function _insert()
{
    $pageId = $this->_pageModel->createPage(
        $this->name,$this->_namespace,$this->parent_id);
    $this->id = $pageId;
    $this->_update();
}

protected function _update()
{
    $data = $this->toArray();
    $this->_pageModel->updatePage($this->id,$data);
}

public function delete()
{
    if(isset($this->id))
    {
        $this->_pageModel->deletePage($this->id);
    }
    else
    {
        throw new Zend_Exception('Niet in staat om item te verwijderen; het item is leeg!');
    }
}
}

在这个脚本中,我试图初始化类:

    public function createAction()
{
    $pageForm = new Form_PageForm();
    $pageForm->setAction('/page/create')
             ->setMethod('post');
    if($this->getRequest()->isPost())
    {
        if($pageForm->isValid($_POST))
        {
            $itemPage = new CMS_Content_Item_Page();
            $itemPage->name = $pageForm->getValue('name');
            $itemPage->headline = $pageForm->getValue('headline');
            $itemPage->description = $pageForm->getValue('description');
            $itemPage->content = $pageForm->getValue('content');
            if($pageForm->image->isUploaded())
            {
                $pageForm->image->receive();
                $itemPage->image = '/images/upload' . basename($pageForm->image->getFileName());
            }
            $itemPage->save();
            return $this->_forward('list');         
        }
    }
    $this->view->form = $pageForm;
}
4

1 回答 1

0

在抽象类 CMS_Content_Item_Abstract::__construct()

Change  $this->_pageModel = new CMS_Content_Item_Page();
to      $this->_pageModel = new Model_Page();

我在“zend CMS Project”一书中遇到了这个问题,我敢打赌这是作者输入错误造成的。

于 2013-05-15T05:33:27.810 回答