Skip to content

Instantly share code, notes, and snippets.

@joelmandell
Created November 2, 2015 21:11
Show Gist options
  • Save joelmandell/b8ccd17c29925f4ee4d1 to your computer and use it in GitHub Desktop.
Save joelmandell/b8ccd17c29925f4ee4d1 to your computer and use it in GitHub Desktop.
CodeIgniter - newsmodel kodsnutt
<?php
class NewsModel extends Model {
var $permission_table;
function NewsModel()
{
parent::Model();
$this->load->database();
$this->load->library('auth');
$this->permission_table="news_permissions";
}
function get_url_prefix()
{
return str_replace("model","",strtolower(get_class($this)));
}
function create_edit_item_links()
{
$function_name="edit"; //This variable is crucial in all model calls that we are using.
(int) $data=0; //Initialize this with zero.
/*If there is a permission that is set to true for the group(s) that the current user belongs to then
the $data
*/
$data=$this->session->userdata($this->permission_table."@".$function_name);
if($data!=0)
{
$text="Here should be links to different news item administration";
} else {
$text="Du har inte rättigheter för att hantera ";
}
// $query = $this->db->query("SELECT * FROM news_items ORDER BY date");
// foreach ($query->result() as $row)
//{
// $text.="".$row->title."<br /><a href=\"".get_class($this)."/edit/".$row->id."\">Redigera</a> | <a href=\"./delete/".$row->id."\">Ta bort</a> | <a href=\"./move/".$row->id."\">Flytta</a><br /><br />";
// }
return $text;
}
function admin_functions()
{
$text="<a href=\"./edit_item_form\">Ändra blogg-post</a>";
return $text;
}
function edit_form($id)
{
$query = $this->db->query("SELECT * FROM blog_items WHERE id LIKE ".$this->db->escape($id)."");
$text="<h1>Ändra post:</h1><br /><form method=\"post\" action=\"\"><p>Rubrik :<input type=\"\" name=\"title\" value=\"".$query->row()->title."\"/></p>
<br /><p>Brödtext:</p><textarea name=\"preamble\" cols=\"70\" rows=\"8\">".$query->row()->preamble."</textarea><br /><br /><p>Sprödtext:</p><textarea name=\"body\" cols=\"70\" rows=\"8\">".$query->row()->body."</textarea></form>";
return $text;
}
function delete_form($id)
{
//Controll session here...
}
function move_form($id)
{
//Controll session here...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment