2016-07-11 58 views
0

如何顯示在視圖function day_s()結果just_organize/administrador/index笨如何顯示結果的功能在視圖

<?php if (! defined('BASEPATH')) exit('No direct script access allowed'); 
class Admin extends MY_Controller { 

public function index() 
{ 
    $this->load->view("layouts/header"); 
    $this->load->view("layouts/navbar"); 
    $this->load->view("just_organize/administrador/index"); 
    $this->load->view("layouts/footer"); 
} 
public function day_s(){ 
    $time = date("H"); 
    $timezone = date("e"); 
    if ($time < "12") { 
     $greeting= "Good morning"; 
    } else 
    if ($time >= "12" && $time < "17") { 
     $greeting= "Good afternoon"; 
    } else 
    if ($time >= "17" && $time < "19") { 
     $greeting= "Good evening"; 
    } else 
    if ($time >= "19") { 
     $greeting= "Good night"; 
    } 
} 
} 

回答

1

只是在你的索引添加這些行:

使用$問候變量鑑於

public function index() 
{ 
    $data['greetings'] = $this->day_s(); 
    $this->load->view("layouts/header"); 
    $this->load->view("layouts/navbar"); 
    $this->load->view("just_organize/administrador/index", $data); 
    $this->load->view("layouts/footer"); 
} 

你day_s函數返回$問候:

public function day_s(){ 
    $time = date("H"); 
    $timezone = date("e"); 
    if ($time < "12") { 
    $greeting= "Good morning"; 
    } else 
    if ($time >= "12" && $time < "17") { 
    $greeting= "Good afternoon"; 
    } else 
    if ($time >= "17" && $time < "19") { 
    $greeting= "Good evening"; 
    } else 
    if ($time >= "19") { 
    $greeting= "Good night"; 
    } 
    return $greeting; 
} 
+0

消息:未定義的變量:問候:( –

+0

檢查$問候空()函數一樣,如果(!空($問候))回聲$問候 – pradeep

+0

現在的工作,謝謝! –