2011-11-29 31 views
5

Tôi có mã lớp sau trong PHP:đòi hỏi một lần cho biết thêm một dòng sản phẩm mới để đáp ứng

<?php 

require_once CUSTOM_PATH . DIRECTORY_SEPARATOR . 'myneighborlists.php'; 

class Action_Get_route extends Frapi_Action implements Frapi_Action_Interface 
{ 

    /** 
    * Required parameters 
    * 
    * @var An array of required parameters. 
    */ 
    protected $requiredParams = array(); 

    /** 
    * The data container to use in toArray() 
    * 
    * @var A container of data to fill and return in toArray() 
    */ 
    private $data = array(); 

    /** 
    * To Array 
    * 
    * This method returns the value found in the database 
    * into an associative array. 
    * 
    * @return array 
    */ 
    public function toArray() 
    { 
     //$this->data['origin'] = $this->getParam('origin', self::TYPE_OUTPUT); 
     //$this->data['destination'] = $this->getParam('destination', self::TYPE_OUTPUT); 
     return $this->data; 
    } 

    /** 
    * Default Call Method 
    * 
    * This method is called when no specific request handler has been found 
    * 
    * @return array 
    */ 
    public function executeAction() 
    { 
     $valid = $this->hasRequiredParameters($this->requiredParams); 
     if ($valid instanceof Frapi_Error) { 
      return $valid; 
     } 

     return $this->toArray(); 
    } 

    /** 
    * Get Request Handler 
    * 
    * This method is called when a request is a GET 
    * 
    * @return array 
    */ 
    public function executeGet() 
    { 
     $valid = $this->hasRequiredParameters($this->requiredParams); 
     if ($valid instanceof Frapi_Error) { 
      return $valid; 
     } 

     return $this->toArray(); 
    } 

    /** 
    * Post Request Handler 
    * 
    * This method is called when a request is a POST 
    * 
    * @return array 
    */ 
    public function executePost() 
    { 
     $valid = $this->hasRequiredParameters($this->requiredParams); 
     if ($valid instanceof Frapi_Error) { 
      return $valid; 
     } 

     return $this->toArray(); 
    } 

    /** 
    * Put Request Handler 
    * 
    * This method is called when a request is a PUT 
    * 
    * @return array 
    */ 
    public function executePut() 
    { 
     $valid = $this->hasRequiredParameters($this->requiredParams); 
     if ($valid instanceof Frapi_Error) { 
      return $valid; 
     } 

     return $this->toArray(); 
    } 

    /** 
    * Delete Request Handler 
    * 
    * This method is called when a request is a DELETE 
    * 
    * @return array 
    */ 
    public function executeDelete() 
    { 
     $valid = $this->hasRequiredParameters($this->requiredParams); 
     if ($valid instanceof Frapi_Error) { 
      return $valid; 
     } 

     return $this->toArray(); 
    } 

    /** 
    * Head Request Handler 
    * 
    * This method is called when a request is a HEAD 
    * 
    * @return array 
    */ 
    public function executeHead() 
    { 
     $valid = $this->hasRequiredParameters($this->requiredParams); 
     if ($valid instanceof Frapi_Error) { 
      return $valid; 
     } 

     return $this->toArray(); 
    } 


} 

này về cơ bản là một lớp mẫu cho một API REST và khi tôi gọi phương thức get phản ứng tôi đã luôn luôn có thêm một dòng mới trong đó. Khi tôi gỡ bỏ require_once, dòng mới thừa đó đã biến mất. Làm cách nào để tránh đường dây mới bổ sung này? This is ý tôi là một dòng mới.

+0

Kiểm tra myneighborlists.php. Có thể có một ngắt dòng phụ trước ' ' –

Trả lời

11

Kiểm tra xem có thêm dòng hoặc khoảng trắng sau thẻ đóng ?> trong tệp được yêu cầu không. Có thể có gì đó trong tệp được yêu cầu hoặc là lặp lại không gian/dòng hoặc có thêm khoảng trống ở cuối tệp.

+3

Cần lưu ý rằng thẻ đóng PHP'?> 'Luôn là tùy chọn ở cuối tệp. Bằng cách bỏ nó ra, bạn có thể giảm một nửa cơ hội của vấn đề này. – Boann

+2

100% đồng ý. Bỏ phiếu. –

+0

Tôi chắc chắn đó là một khoảng trắng khoảng trống ở cuối tệp của bạn! – powtac

0

Thật khó để trả lời câu hỏi này mà không thấy mã nguồn của myneighborlists.php. Tôi đoán là, có một dòng trống ở đầu tệp này trước khi <?php

Các vấn đề liên quan