[eluser]Hamed[/eluser]
in view I have :
Code:
<dd class="createdby"><?php echo $this->content->getDep($content->dep); ?></dd>
and code full code for main class :
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Main extends CI_Controller {
public $silde;
public $dep;
public $photo;
public $user = False;
public $usergroup;
public function __construct()
{
parent::__construct();
$this->silde = $this->db->get('slide')->result();
$this->dep = $this->db->get('dep')->result();
$this->photo = $this->db->query("SELECT * FROM `gallery` WHERE dep='1' ORDER BY pid DESC LIMIT 5")->result();
}
public function index()
{
$contents = $this->db->query("SELECT * FROM `content` WHERE dep='1' AND enable='1' ORDER BY date DESC LIMIT 5");
$contents = $contents->result();
$data['contents'] = $contents;
$data['dep_id'] = '1';
$this->load->view('main/index', $data);
}
public function test()
{
$this->load->view('main/index');
}
}
/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */
also full code of content (model):
Code:
<?php
/**
* @author Ghasemzadeh
* @copyright 2012
*/
class Content extends CI_Model {
function __construct()
{
parent::__construct();
}
function getDate($date)
{
$od = self::makeDate($date);
return $od['y']."/".$od['m']."/".$od['d'];
}
function getDep($did)
{
$deps = $this->db->query("SELECT * FROM `dep` WHERE did='$did'");
$dep = $deps->result();
return $dep->title;
}
public static function div($a,$b)
{
return (int) ($a / $b);
}
public static function jalali($g_y, $g_m, $g_d)
{
global $Lang;
$g_days_in_month = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
$j_days_in_month = array(31, 31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 29);
$gy = $g_y-1600;
$gm = $g_m-1;
$gd = $g_d-1;
$g_day_no = 365*$gy+self::div($gy+3,4)-self::div($gy+99,100)+self::div($gy+399,400);
for ($i=0; $i < $gm; ++$i)
$g_day_no += $g_days_in_month[$i];
if ($gm>1 && (($gy%4==0 && $gy0!=0) || ($gy@0==0)))
++$g_day_no;
$g_day_no += $gd;
$j_day_no = $g_day_no-79;
$j_np = self::div($j_day_no, 12053);
$j_day_no %= 12053;
$jy = 979+33*$j_np+4*self::div($j_day_no,1461);
$j_day_no %= 1461;
if ($j_day_no >= 366)
{
$jy += self::div($j_day_no-1, 365);
$j_day_no = ($j_day_no-1)65;
}
for ($i = 0; $i < 11 && $j_day_no >= $j_days_in_month[$i]; ++$i)
{
$j_day_no -= $j_days_in_month[$i];
}
$jm = $i+1;
$jd = $j_day_no+1;
return array('y'=>$jy, 'm'=>$jm, 'd'=>$jd);
}
public static function make_date($mounth,$day)
{
$new_mounth = $mounth;
if($new_mounth == '1')
{
$new_mounth = "فروردین";
}
elseif($new_mounth == '2')
{
$new_mounth = "اردیبهشت";
}
elseif($new_mounth == '3')
{
$new_mounth = "خرداد";
}
elseif($new_mounth == '4')
{
$new_mounth = "تیر";
}
elseif($new_mounth == '5')
{
$new_mounth = "مرداد";
}
elseif($new_mounth == '6')
{
$new_mounth = "شهریور";
}
elseif($new_mounth == '7')
{
$new_mounth = "مهر";
}
elseif($new_mounth == '8')
{
$new_mounth = "آبان";
}
elseif($new_mounth == '9')
{
$new_mounth = "آدز";
}
elseif($new_mounth == '10')
{
$new_mounth = "دی";
}
elseif($new_mounth == '11')
{
$new_mounth = "بهمن";
}
elseif($new_mounth == '12')
{
$new_mounth = "اسفند";
}
$weekdays = date("D");
if($weekdays == 'Sun')
{
$weekdays = "یک شنبه";
}
elseif($weekdays == 'Mon')
{
$weekdays = "دو شنبه";
}
elseif
($weekdays == 'Tue'){
$weekdays = "سه شنبه";
}
elseif($weekdays == 'Wed')
{
$weekdays = "چهار شنبه";
}
elseif($weekdays == 'Thu')
{
$weekdays = "پنج شنبه";
}
elseif($weekdays == 'Fri')
{
$weekdays = "جمعه";
}
elseif($weekdays == 'Sat')
{
$weekdays = "شنبه";
}
return array ("mo"=>$new_mounth,"w"=>$weekdays);
}
public static function makeDate($t)
{
//change it to array
$y = date('Y',$t);
$m = date('m',$t);
$d = date('d',$t);
$jdate = self::jalali($y, $m, $d);
$date = self::make_date($jdate['m'],$jdate['d']);
$odate['m'] = $jdate['m'];
$odate['y'] = $jdate['y'];
$odate['d'] = $jdate['d'];
$odate['weekday'] = $date['w'];
$odate['mo'] = $date['mo'];
return $odate;
}
}
?>
I get this error:
Quote: A PHP Error was encountered
Severity: Notice
Message: Trying to get property of non-object
Filename: models/content.php
Line Number: 25