免责声明:我是Web开发的新手
到目前为止:我一直在将MySQL数据库表中的主键数据传递到生成日历时显示在日历类库列表项的id =“”字段中,而且我也一直在传递另一个与列表项的相应主键的行相关联的值。
场景:我需要将主键的相同行中的另一个值传递到列表项的class =“”,然后我就碰壁了。我可能需要在我的模态中创建一个新函数,或者在生成所述日历的控制器中执行某些操作,或者我可能完全忽略了一些非常简单的操作。无论如何,我可以使用一些非常赞赏的帮助。非常感谢你!
P.S。如果您需要更多信息来帮助我,请告诉我。再次感谢!你太棒了!
型号:
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;
}
}
}
答案 0 :(得分:4)
如果我理解正确,当你的视频以html形式输出时,你想要为你的事件添加“更多”,所以你要添加引用pk作为ID(因此我在上面的评论)。
您可以为每个事件创建一个关联数组,如下所示:
$cal_events = array();
foreach ($events as $e)
{
if ( date("Y", $e->date) == $year && date("m", $e->date) == $month)
{
$day = intval( date("d", $e->date));
//just made up examples below
$cal_events[$day][$e->id]['class'] = $e->class;
$cal_events[$day][$e->id]['type'] = $e->type;
$cal_events[$day][$e->id]['id'] = $e->title;
}
}
return $cal_events;
稍后您将在日历库中引用该数组,如下所示:
// 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="'.$value['class'].'" id="'.$value['id'].'">'.$value['type'].'</li>';
}
$out .= str_replace('{day}', $day, str_replace('{content}', $several_events, $temp));
}
希望这就是你要找的东西。