2011-05-05 6 views
0

CodeIgniter 프레임 워크를 사용하고 있습니다. common_funtions 라이브러리를 만들었습니다. 이 라이브러리를 사용하여 다른 컨트롤러에서 함수를 호출 할 수 있습니다. 특히 하나 개의 함수는 인수를 필요로하지만 내가 함수를 호출 할 때 세 가지 오류를 받고 있어요 : 라이브러리에서 : 여기 codeigniter에서 함수에 인수를 전달하는 데 문제가 있습니다.

 
A PHP Error was encountered 
Severity: Warning 
Message: Missing argument 1 for Common_functions::time_ago(), called in \...\get_comments.php on line 11 and defined 
Filename: libraries/Common_functions.php 
Line Number: 20 

A PHP Error was encountered 
Severity: Notice 
Message: Undefined variable: time 
Filename: libraries/Common_functions.php 
Line Number: 26 

A PHP Error was encountered 
Severity: Notice 
Message: Undefined variable: time 
Filename: libraries/Common_functions.php 
Line Number: 39 

내 코드입니다 common_functions.php

// The following function calculates ‘how long ago’ 
function time_ago($time) 
{  
    $periods = array('second', 'minute', 'hour', 'day'); 
    $lengths = array('60', '60', '24', '7'); 
    $tense = 'ago'; 
    $now = time(); 
    $time_diff = $now - $time; 
    for ($j = 0; $time_diff >= $lengths[$j] && $j < count($lengths)-1; $j++) 
    { 
     $time_diff /= $lengths[$j]; 
    } 
    $time_diff = round($time_diff); 
    if ($time_diff != 1) 
    { 
     $periods[$j].='s'; 
    } 
    if ($time_diff > 7 && $periods[$j] == 'days') 
    { 
     $time_ago = date("l dS F, Y", $time); 
    } 
    else 
    { 
     $time_ago = $time_diff." ".$periods[$j]." ago"; 
    } 
    return $time_ago; 
} 

에서 내 컨트롤러 :

$query = $this->db->query(“ 
    SELECT * 
    FROM post_comments 
    WHERE p_id = ‘$id’ 
    ORDER BY date ASC”); 
$comments = $query->result_array(); 
foreach ($comments as $comment) 
{ 
    $comment['date'] = $this->common_functions->time_ago($comment['date']); 
} 

내 코드에 문제가 있습니까? 아니면 프레임 워크의 버그일까요? 이 문제가 처음 발생한 것은 아닙니다.

+0

은'당신의 foreach 문에'위해서 var_dump ($ 주석)를 넣습니다. 원하는 방향으로 돌아 오면 배열을 인쇄해야합니다. 인쇄중인 것의 인스턴스를 게시하십시오 (코드가 루프를 거쳐 여러 번 인쇄되기 때문에 인쇄물 중 하나만 필요합니다). – Shauna

답변

관련 문제