2011-11-03 59 views
0

我刚刚创建这个文件夹(应用程序/库)以及所有下面的步骤来创建个人图书馆对我自己的图书馆,叫我自己的图书馆在一个视图中的笨

一次我在控制它执行加载该库功能,而是试图将它传递给视图时,没有返回

这里是我的代码

我自己的函数

<?php if (! defined('BASEPATH')) exit('No direct script access allowed'); 

    class Common { 

      public function date_arabic() 
      { 
      $daysarabic=array('الأحد','الاثنين','الثلاثاء' 
      ,'الأربعاء','الخميس','الجمعة','السبت'); 
      $monarabic=array('','يناير','فبراير','مارس', 
      'أبريل','مايو','يونيو','يوليو' 
      ,'أغسطس','سبتمبر','أكتوبر','نوفمبر','ديسمبر'); 
      $date=getdate(time()); 
      echo $daysarabic[$date['wday']].' '.$date['mday'].' '.$monarabic[$date['mon']].' '.$date['year']/*.' الوقت الأن '.$date['hours'].':'.$date['minutes'].':'.$date['seconds']*/; 
      }  

    } 

我的控制器

//arabic date 
    $this->load->library('Common'); 
    $this->common->date_arabic(); 

这里它打印出在我自己的函数中的数据,我想这些信息存储在一个$数据将它传递给像

//arabic date 
    $this->load->library('Common'); 
    $data['date_arabic'] = $this->common->date_arabic(); 
    ... 

    $this->load->view('home_page.php', $data); 

的观点则当要查看我只需键入

<?php echo $date_arabic ; ?> 

,但没有返回

回答

0

在你的函数,改变从这个最后一行:

echo $daysarabic[$date['wday']].' '.$date['mday'].' '.$monarabic[$date['mon']].' '.$date['year']/*.' الوقت الأن '.$date['hours'].':'.$date['minutes'].':'.$date['seconds']*/; 

这样:

return $daysarabic[$date['wday']].' '.$date['mday'].' '.$monarabic[$date['mon']].' '.$date['year']/*.' الوقت الأن '.$date['hours'].':'.$date['minutes'].':'.$date['seconds']*/; 
+0

非常感谢,它对我很好 – ahmedsaber111

0
when you are writing libraries, you have to manually grab the Codeigniter instance like this 

$CI =& get_instance(); 

then you would use $CI where you would normally use $this to interact with loaded codeigniter resources 

so... 

instead of 

$this->input->post(); 
you would write 

$CI->input->post(); 


EXAMPLE LIBRARY STRUCTURE 

class Examplelib { 

    // declare your CI instance class-wide private 
    private $CI; 

    public function __construct() 
    { 
     // get the CI instance and store it class wide 
     $this->CI =& get_instance(); 
    } 

    public function lib_function() 
    { 
     // use it here 
     $this->CI->db->etc() 
    } 

    public function another_func() 
    { 
     // and here 
     $this->CI->input->post(); 
    } 

} 
+0

这是艰难的啮合了解......请如果你能在我的例子自己的代码 – ahmedsaber111