在Codeigniter的视图中调用我自己的库 [英] call my own library within a view in codeigniter
本文介绍了在Codeigniter的视图中调用我自己的库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我刚刚在此文件夹(应用程序/库)上创建了自己的库,并按照所有步骤创建了单个库,
i just created my own library on this folder (application/library) and following all steps to create individual library,
一旦我将此库加载到控制器中,它就会执行该功能,但是当尝试将其传递给视图时,什么也不会返回
once i load this library in my controller it execute the function, but when trying to pass it to the view, nothing return
这是我的代码
我自己的功能
<?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();
在这里它以我自己的函数打印出数据,我试图将其存储在$ data中,以将其传递给这样的视图
here it prints out the data in my own function, i tried to store this in a $data to pass it to the view like that
//arabic date
$this->load->library('Common');
$data['date_arabic'] = $this->common->date_arabic();
...
$this->load->view('home_page.php', $data);
然后在查看时我只输入
<?php echo $date_arabic ; ?>
但什么也没返回
推荐答案
在您的函数中,更改最后一行:
In your function, change the last line from this:
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']*/;
这篇关于在Codeigniter的视图中调用我自己的库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文