2015-10-26 41 views
-4

我在面向對象的PHP中創建了一個註冊登錄系統。我需要從PHP方法調用HTML代碼。從php方法調用的HTML代碼

這裏是View.php類:

<?php 
class View{ 

public function createLoginUI(){ 
    ?> 
    <html> 
    <title></title> 
    <head></head> 
    <body> 
    <form> 
     Email:<input type="text" name="mail"> 
     Pass:<input type="text" name="pass"> 
     <input type="submit" name="login" value="Login"><br> 
     <a href="?regist" >Regist</a> 

    </form> 
    </body> 
    </html> 
    <?php 
} 

public function createRegistUI() 
{ 
    ?> 
    <html> 
    <title></title> 
    <head></head> 
    <body> 
    <form> 
     Name:<input type="text" name="name"> 
     Email:<input type="text" name="email"> 
     Pass:<input type="text" name="pw"> 
     <input type="submit" name="send" value="Send"> 
    </form> 
    </body> 
    </html> 
    <?php 

} 

} 

而且index.php文件:

<?php 
require_once "model/Autoload.php"; 

$view = new View(); 
$view->createLoginUI(); 

在createLoginUI有着某種聯繫。鏈接功能是加載註冊表界面。我做了這個:

public function newSite($view) { 

    if(isset($_GET['regist'])) { 

    $view->createRegist(); 

    } 

} 

我在index.php中調用這個方法。如果我點擊「註冊」按鈕,它會顯示兩個視圖。我想只看到「註冊」視圖。我嘗試了header(),但是我不知道如何在頭文件中調用方法,並且不確定它會起作用。

+1

那就不叫'createLoginUI()'註冊頁面。你得到兩個,因爲你告訴PHP輸出兩個。 –

+0

[有什麼方法可以在PHP函數中返回HTML? (不建立作爲字符串返回值)](http://stackoverflow.com/questions/528445/is-there-any-way-to-return-html-in-a-php-function-without-building-返回) – johnny

+0

我並不完全清楚你在問什麼,但爲什麼不在調用createRegist()之前創建一個新視圖?不應該'$ view = new View();'在該行之前出現? –

回答

1

嘗試這種方式

<?php 
    class View{ 


    public function createLoginUI(){ 
    echo '<html> 
      <title></title> 
      <head></head> 
      <body> 
      <form> 
       Email:<input type="text" name="mail"> 
       Pass:<input type="text" name="pass"> 
       <input type="submit" name="login" value="Login"><br> 
       <a href="?regist" >Regist</a> 

      </form> 
      </body> 
      </html>'; 
    } 
    ..... 
    ..... 
} 
+0

我試過了,但總是顯示兩個視圖。我嘗試了很多自從昨天以來在這裏寫的東西,但沒有一個能夠正常工作。我開始放棄這一點。 – Bbeni

+0

@Bbeni刪除所有的HTML,並直接回顯'測試';並看看會發生什麼。你有兩個嗎?你從哪裏打電話給他們? – johnny