برگزیده های پرشین تولز

تاریخ فارسی در Codeigniter

majid.empire

Registered User
تاریخ عضویت
10 ژانویه 2009
نوشته‌ها
189
لایک‌ها
18
محل سکونت
آنجا که مرا منتظرند
سلام دوستان .
دوستانی که در مورد Codeigniter framework اطلاعات دارند میدونن چه جوری میشه توش از تاریخ فارسی استفاده کرد .
من یه اسکریپت دارم که با این فریم ورک نوشته شده و میخوام تاریخ ها توش بصورت جلالی نشون داده بشه .
توی ویکی خود codeigniter لینک زیر رو پیدا کردم .
http://codeigniter.com/wiki/Calendar/
ولی نمیدونم چه جوری میشه استفاده کرد ازش .
این پایین یه قسمت از کدی که میخوام تاریخش فارسی بشه مینویسم .
PHP:
	<?=date('H:m', strtotime($news->news_created))?>

اگه کسی اطلاعات داره لطفا یه راهنمایی دقیق بکنه . اگر هم از اون library توی اون ویکی نمیشه استفاده کرد لطفا نحوه استفاده از تابع Jdate رو بگید که با اون درستش کنم .
ممنون
 

firebird

Registered User
تاریخ عضویت
2 جولای 2005
نوشته‌ها
1,424
لایک‌ها
10
سن
46
شما تابع JDate رو بذار تو یه helper. یه خط لود اضافه کن به کنترلرت. بعد راحت ازش استفاده کن.
 

majid.empire

Registered User
تاریخ عضویت
10 ژانویه 2009
نوشته‌ها
189
لایک‌ها
18
محل سکونت
آنجا که مرا منتظرند
شما تابع JDate رو بذار تو یه helper. یه خط لود اضافه کن به کنترلرت. بعد راحت ازش استفاده کن.

خیل ممنون دوست عزیز از پاسخی که دادین ولی قضیه برای خیلی وقت پیشه ؛ مشکلم رو همین طور که شما گفی حل کردم .الان فقط یه مشکل با کدی که دارم ، دارم و اونم PAGINATION هستش که خیلی اذیت میکنه . شما میتونی مشکلم رو حل کنی . اگر میتونی من کنترلر و مدل رو براتون بفرستم که این قضیه رو یه کمکی به من بکنید . اگه بشه با همون کنترلر Codeigniter درست بشه .
ممنون
 

firebird

Registered User
تاریخ عضویت
2 جولای 2005
نوشته‌ها
1,424
لایک‌ها
10
سن
46
من تاریخ پستتو دیدم متوجه شدم قدیمیه. دیدم کسی جواب نداده گفتم راه حلو بنویسم که شاید به درد کس دیگه ای بخوره. شما هم مشکل دیگتو همین جا بگو اگه بلد بودم حتماً جواب میدم.
 

majid.empire

Registered User
تاریخ عضویت
10 ژانویه 2009
نوشته‌ها
189
لایک‌ها
18
محل سکونت
آنجا که مرا منتظرند
خیلی ممنون . شما لطف داری . باشه اگر بتونم تا امشب مینویسم . اگر نشد فردا مینویسم شما هر وقت دیدی اگه تونستی مشکل ما رو حل کن . ممنون
 

majid.empire

Registered User
تاریخ عضویت
10 ژانویه 2009
نوشته‌ها
189
لایک‌ها
18
محل سکونت
آنجا که مرا منتظرند
سلام .
این فایل جستجوی اسکریپتیه که من دارم . میخوام صفحه بندی رو توش اضافه کنم موندم:rolleyes:
کنترلر رو هم پایین تر آوردم .
ببینید چیزی سر در میارید .

این فایل view منه
PHP:
<?=partial('months')?>
<?=partial('search_filter_', array('county'=>$county,
								   'categories'=>$categories,
								   'municipalities'=>$municipalities,
								   'advert_types'=>$advert_types))?>
<script type="text/javascript">
	$(document).ready(function()
	{
		$('#all').click(function()
		{
			$('#advert_target').val('<?=ADVERT_TARGET_ALL_SLUG?>');
			$('#search_form').submit();
		});
		
		$('#private').click(function()
		{
			$('#advert_target').val('<?=ADVERT_TARGET_PRIVATE_SLUG?>');
			$('#search_form').submit();
		});
		
		$('#company').click(function()
		{
			$('#advert_target').val('<?=ADVERT_TARGET_COMPANY_SLUG?>');
			$('#search_form').submit();
		});
		
		$('#advert_sort_time').click(function(e)
		{
			$('#advert_sort').val('<?=ADVERT_SORT_TIME?>');
			$('#search_form').submit();
			e.preventDefault();
		});
		
		$('#advert_sort_price').click(function(e)
		{
			$('#advert_sort').val('<?=ADVERT_SORT_PRICE?>');
			$('#search_form').submit();
			e.preventDefault();
		});
	});
	</script>
<div id="result">
  <div id="summary">
    <div id="all" class="box <?=literal('advert_target') == ADVERT_TARGET_ALL_SLUG ? 'active':null?>"> all items  (
      <?=$count['all']?>
      ) </div>
    <div id="private" class="box <?=literal('advert_target') == ADVERT_TARGET_PRIVATE_SLUG ? 'active':null?>"> personal items (
      <?=$count['private']?>
      ) </div>
    <div id="company" class="box <?=literal('advert_target') == ADVERT_TARGET_COMPANY_SLUG ? 'active':null?>"> commercial items (
      <?=$count['company']?>
      ) </div>
    <div id="sort">
      <?php if(strtolower(literal('advert_sort')) == ADVERT_SORT_PRICE):?>
      <?=anchor('', lang('search_sort_time'), 'id="advert_sort_time"')?>
      <?php else:?>
      <?=anchor('', lang('search_sort_price'), 'id="advert_sort_price"')?>
      <?php endif;?>
    </div>
    <div style="clear:both">&nbsp;</div>
  </div>
  <div id="adverts">
    <?php if($adverts):?>
    <?php $i=1; foreach($adverts as $advert):?>
    <div class="advert">
      <div class="time">
        <?php if(date('Y-m-d') == date('Y-m-d', strtotime($advert->advert_created))):?>
        today<br />
        <?php elseif (date('Y-m-d', strtotime('-1 day')) == date('Y-m-d', strtotime($advert->advert_created))):?>
        yesterday<br />
        <?php else:?>
        <?=jdate('  d M   Y' ,strtotime($advert->advert_created))?>
        <br />
        <?php endif;?>
        <? echo "hour: ".jdate('H:i', strtotime($advert->advert_created))?> </div>
      <?php if($advert->image):?>
      <div class="image" onclick="location.href='<?=site_url('advert/detail/'.$advert->advert_slug)?>';"> <a href="<?=site_url('advert/detail/'.$advert->advert_slug)?>"><img src="<?=site_url('advert/thumb/'.$advert->image->advert_image_id)?>" /></a> </div>
      <?php else:?>
      <div class="blank"> &nbsp; </div>
      <?php endif;?>
      <div class="text"> <span class="title">
        <?=anchor('advert/detail/'.$advert->advert_slug, $advert->advert_subject)?>
        </span> <br />
        <br />
        <span class="price">
        <?=$advert->advert_price ? number_format($advert->advert_price,0,'','.').CURR : null?>
        </span> </div>
      <div class="municipality">
        <?=$advert->municipality_name?>
        <br />
        <br />
        <?=$advert->target_name?>
        <br />
        <br />
        <?=$advert->category_name?>
      </div>
    </div>
    <div class="advert_divider"> &nbsp; </div>
    <?php $i++; endforeach;?>
    <?php else:?>
    <div id="body_wrapper">
      <h1>no item</h1>
    </div>
    <?php endif;?>
  </div>
</div>
<div style="clear:both"></div>

این هم فایل کنترلر جستجو
PHP:
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Search extends Application
{
	public function __construct()
	{
		parent::__construct();
		$this->load->model('meta_model');
		$this->load->model('category_model');
		$this->load->model('advert_model');
		$this->load->helper('Fdate');
		$this->load->helper('form');
		$this->load->helper('advert');
		$this->load->library('form_validation');
		$this->load->helper('security');
		$this->config->add_to_item(KCI_LANG, 'search');
	}
	
	/**
	 * Returns the search with based on the requested county.
	 * If the county was recently visited, the municipality and locality aren't updated.
	 * 
	 * The primary search is also made to determine the latest search.
	 *
	 * @param unknown_type $slug
	 */
	public function index($county, $target = ADVERT_TARGET_ALL_SLUG, $sort = null, $type = null, $category = null, $municipality = null, $text = null)
	{
	
		$county = $this->meta_model->county(xss_clean($county));
		if(!$county)
			redirect('');
		$this->load_banner(array($county->county_id,BANNER_SECTION_SEARCH));	
		if(!get_county() || get_county()->county_id != $county->county_id)
			set_county($county);
			
		$this->form_validation->set_rules('text', lang('advert_freetext'), 'max_length[100]');		
			
		$adverts = array();
		$count = array();
		if($this->form_validation->run())
		{
			$url = array();
			$url[] = $county->county_slug;
			$url[] = $this->input->post('advert_target') ? $this->input->post('advert_target') : ADVERT_TARGET_ALL_SLUG;
			$url[] = $this->input->post('advert_sort') ? $this->input->post('advert_sort') : ADVERT_SORT_TIME;
			$url[] = $this->input->post('advert_type') ? implode('-',$this->input->post('advert_type')) : ADVERT_TYPE_SALE;
			$url[] = $this->input->post('category_id') ? $this->input->post('category_id', true) : 0;
			$url[] = $this->input->post('municipality_id') ? $this->input->post('municipality_id', true) : 0;
		
			
			
			if($this->input->post('text'))
				$url[] = urlencode($this->input->post('text', true));
				
			$slug = '/'.implode('/', $url);
			redirect($slug);
		}
		else 
		{
			$params = array();
			
			//Convert to objects
			if($type)
			{
				$type = explode('-', xss_clean($type));
				if($type)
				{
					$params['advert_type'] = $type;
					
					foreach($type as $t)
					populate('advert_type['.$t.']', true);
				}
			}
			else 
			{
				$params['advert_type'] = array(ADVERT_TYPE_SALE);
				populate('advert_type['.ADVERT_TYPE_SALE.']', true);
			}
			
			
			if($category)
				$category = $this->category_model->get(xss_clean($category));
			populate('category_id', $category ? $category->category_id : null);
			$params['category_id'] = $category ? $category->category_id : null;
			
			if($municipality == ADVERT_CODE_ENTIRE_COUNTY)
			{
				$params['county_id'] = $county->county_id;
				populate('municipality_id', ADVERT_CODE_ENTIRE_COUNTY);
			}
			else if($municipality == ADVERT_CODE_ENTIRE_COUNTRY)
				populate('municipality_id', ADVERT_CODE_ENTIRE_COUNTRY);
			else if($municipality)
			{
				$municipality = $this->meta_model->municipality(xss_clean($municipality));
				if($municipality)
				{
					$params['municipality_id'] = $municipality->municipality_id;
					populate('municipality_id', $municipality->municipality_id);
				}
			}
			else 
				$params['county_id'] = $county->county_id;
			
			if($target && $target != ADVERT_TARGET_ALL_SLUG)
			{
				$target = $this->advert_model->slug_target(xss_clean($target));
				if($target)
				{
					populate('advert_target',  $target->target_slug);
					$params['advert_target'] = $target->target_id;
				}
			}
			else 
				populate('advert_target', ADVERT_TARGET_ALL_SLUG);

			$params['advert_sort'] = $sort ? $sort : ADVERT_SORT_TIME;
			populate('advert_sort', $params['advert_sort']);
			$params['text'] = $text ? xss_clean($text) : null;
			populate('text', $text ? xss_clean($text) : null);
						
			$adverts = $this->advert_model->search($params, $count);
		}
		
		$months = months();
		$advert_types = $this->advert_model->types();
		$municipalities = $this->meta_model->municipalities($county);
		$categories = $this->category_model->all();
		$this->_view('search_view', array(
								  'months' => $months,
								  'municipalities' => $municipalities, 
								  'categories'=>$categories,
								  'county' => $county,
								  'adverts' => $adverts,
								  'advert_types'=>$advert_types,
								  'count' => $count));
	}
	
	
	
	
	
	
	
	
	/**
	 * Returns the municipalities as JSON for a specified county
	 * This is used by the AJAX request on the search filter
	 *
	 */
	public function municipalities()
	{
		$result = array();
		$county_id = $this->input->post('id', true);
		
		if($county_id == 0)
		{
			$result['message'] = lang('ar_county_not_choosen');
			set_county(null);
		}
		else 
		{
			$county = $this->meta_model->county_by_id($county_id);

			if(!$county)
			{
				$result['error'] = lang('ar_county_not_found');	
			}
			else 
			{
				set_county($county);
				
				$result['county_name'] = utf8_encode($county->county_name);
				
				foreach($this->meta_model->municipalities_for_json($county) as $municipality)
					$result['municipalities'][] = array_map('utf8_encode', $municipality);
			}
		}

		echo json_encode($result);
		die();
	}
	
	/**
	 * Returns the localities as JSON for a specified municipality
	 * This is used by the AJAX request on the search filter
	 *
	 */
	public function localities()
	{
		$result = array();
		$municipality_id = $this->input->post('id', true);
		
		if($municipality_id == 0)
		{
			$result['message'] = lang('ar_municipality_not_choosen');
			set_municipality(null);
		}
		else 
		{
			$municipality = $this->meta_model->municipality($municipality_id);

			if(!$municipality)
			{
				$result['error'] = lang('ar_municipality_not_found');	
			}
			else 
			{
				set_municipality($municipality);
				
				$result['municipality_name'] = utf8_encode($municipality->municipality_name);
				
				foreach($this->meta_model->localities_for_json($municipality) as $locality)
					$result['localities'][] = array_map('utf8_encode', $locality);
			}
		}

		echo json_encode($result);
		die();
	}
	
	/**
	 * Updates the session container with the 
	 * latest requested locality. Used by 
	 * the AJAX request in the search filter
	 * 
	 *
	 */
	public function locality_set()
	{
		$locality_id = $this->input->post('id', true);
		
		if($locality_id == 0 || !is_numeric($locality_id))
			set_locality(null);
			
		$locality = $this->meta_model->locality($locality_id);
		
		if(!$locality)
			set_locality(null);
		else 
			set_locality($locality);
	}
	
	/**
	 * Updates the session container with the 
	 * latest requested category. Used by 
	 * the AJAX request in the search filter
	 * 
	 *
	 */
	public function category_set()
	{
		$category_id = $this->input->post('id', true);
		
		if($category_id == 0 || !is_numeric($category_id))
			set_category(null);
			
		$category = $this->category_model->get($category_id);
		
		if(!$category)
			set_category(null);
		else 
			set_category($category);
	}
	
	/**
	 * Lodge search that returns the info as JSON.
	 * Used by the AJAX request in the search filter.
	 *
	 */
	public function process_search()
	{
		$text = utf8_decode($this->input->post('text', true));
		$offset = utf8_decode($this->input->post('offset', true));
		
		if(!is_numeric($offset))
			$offset = 0;
		
		$result = array();
		$result_count = 0;
		$lodges = $this->lodge_model->search($text, 10, $offset, true, $result_count);
		
		$result['result_count'] = $result_count;
		
		foreach($lodges as $lodge)
		{
			$tmp = array_map('utf8_encode', get_object_vars($lodge));
			
			foreach($this->lodge_model->facilities($lodge) as $facility)
				$tmp['facilities'][] = array_map('utf8_encode', get_object_vars($facility));
			
			foreach($this->lodge_model->distances($lodge) as $distance)
				$tmp['distances'][] = array_map('utf8_encode', get_object_vars($distance));
				
			foreach($this->lodge_model->prices($lodge) as $price)
				$tmp['prices'][] = array_map('utf8_encode', get_object_vars($price));
				
			$image = $this->lodge_model->image($lodge);
			if($image)
				$tmp['image'] = array_map('utf8_encode', get_object_vars($image));
				
			$result['lodges'][] = $tmp;
		}
			
		echo json_encode($result);
	}
	
}
 
بالا