iml*_*ell 1 php mysql database codeigniter
免责声明:我是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;
}
Run Code Online (Sandbox Code Playgroud)
控制器:
$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');
Run Code Online (Sandbox Code Playgroud)
日历库:
// 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));
}
Run Code Online (Sandbox Code Playgroud)
其他日历库信息:
// --------------------------------------------------------------------
/**
* 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;
}
}
}
Run Code Online (Sandbox Code Playgroud)
如果我正确理解,您想在事件以视觉形式输出为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;
Run Code Online (Sandbox Code Playgroud)
然后,您稍后将在日历库中引用该数组,如下所示:
// 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));
}
Run Code Online (Sandbox Code Playgroud)
希望这就是您想要的。