【发布时间】:2011-12-01 10:14:32
【问题描述】:
免责声明:我是 Web 开发新手
到目前为止:我一直在将 MySQL 数据库表中的主键数据传递到生成时显示在日历上的日历类库列表项的 id="" 字段中,并且我还传递了另一个与列表项的相应主键的行关联的值也是如此。
场景:我需要将另一个值从主键的同一行传递到列表项的 class="" 中,但我碰壁了。我可能需要在我的模式中创建一个新功能,或者在生成所述日历的控制器中做一些事情,或者我可能完全忽略了一些完全简单的事情。无论如何,我可以使用一些非常感谢的帮助。非常感谢!
附:如果您需要更多信息来帮助我,请告诉我。再次感谢!你们都很棒!
型号:
class Events_model extends crud_model {
public function __construct()
{
parent::__construct();
$this->pk = 'id';
$this->table_name = 'events';
}
public function get_events_for_calendar($user_id, $year = FALSE, $month = FALSE)
{
if ( ! $year )
{
$year = date("Y");
}
if ( ! $month )
{
$month = date("m");
}
$this->db->where("user_id", $user_id);
$events = parent::get_all();
$cal_events = array();
foreach ($events as $e)
{
if ( date("Y", $e->date) == $year && date("m", $e->date) == $month)
{
$day = intval( date("d", $e->date));
//Swap out to change between displaying type or title of events listed -lrussell810
//$cal_events[$day][$e->id] = $e->type;
$cal_events[$day][$e->id] = $e->title;
}
}
return $cal_events;
}
控制器:
$this->load->library('calendar', $config);
$title['title'] = 'Planner';
$data = $this->events->get_events_for_calendar($this->end_user->id, $this->uri->segment(4), $this->uri->segment(5));
$calendar['calendar'] = $this->calendar->generate($this->uri->segment(4), $this->uri->segment(5), $data);
$this->load->view('public/head_view', $title);
$this->load->view('user/header_view');
$this->load->view('user/planner_view', $calendar);
$this->load->view('user/footer_view');
日历库:
// If more than one event on the same day
if (is_array($data[$day]))
{
$several_events = '';
foreach ($data[$day] as $key => $value)
{
$several_events .= '<li class="" id="'.$key.'">'.$value.'</li>';
}
$out .= str_replace('{day}', $day, str_replace('{content}', $several_events, $temp));
}
其他日历库信息:
// --------------------------------------------------------------------
/**
* Initialize the user preferences
*
* Accepts an associative array as input, containing display preferences
*
* @access public
* @param array config preferences
* @return void
*/
function initialize($config = array())
{
foreach ($config as $key => $val)
{
if (isset($this->$key))
{
$this->$key = $val;
}
}
}
【问题讨论】:
-
你能澄清你的问题吗?你到底想做什么?向
'<li class="" id="'.$key.'">'.$value.'</li>'类添加值?此外,您可能应该将您的 id 称为event_'.$key.',因为数字 ID 不正确(就像在编程中说1 = "cat") -
是的,我正在尝试在课程引用中添加另一个值,我一定会在那里更改我的 id :) 感谢您的提示!
-
嗨@Jakub想知道你把这段代码放在哪里
-
// 如果同一天有多个事件 if (is_array($data[$day])) { $several_events = ''; foreach ($data[$day] as $key => $value) { $several_events .= '
- '.$value.'
' ; } $out .= str_replace('{day}', $day, str_replace('{content}', $several_events, $temp)); }
标签: php mysql database codeigniter