Welcome Guest, Not a member yet? Register   Sign In
how to load view in my own image library???
#1

[eluser]meer[/eluser]
i wanna createa image style library
i have a function whch add images and its data in the controller , which loads views to get data from the form

now when creating my library ,, im confused how to do this

this is my simple controller code
controller .......
Code:
function add_images()
{
  $this->load->helper(array('form', 'url'));
  $this->load->library('form_validation');
  $this->form_validation->set_rules('hover','hover','required');
  $this->form_validation->set_rules('description','Description','required');
  $this->form_validation->set_rules('image', 'Image', 'callback__do_upload');
  if ($this->form_validation->run() == FALSE)
  {
  $this->load->view('myform1');
  }  
  else
  {
  $temp=$this->upload->data();
  $filename=$temp['file_name'];
  $fullpath=$temp['full_path'];
  $hover = $this->input->post('hover');
  $description = $this->input->post('description');
  $this->load->model('admin_model');
  $this->admin_model->add_image($filename,$fullpath,$hover,$description);
  $data = array('upload_data' => $this->upload->data());
  $this->load->view('upload_success',$data);
  }
   }

  public function _do_upload()
   {
   $config['upload_path'] = './images/';
   $config['allowed_types'] = 'gif|jpg|png';
   $config['max_size'] = '100';
   $config['max_width']  = '1024';
   $config['max_height']  = '768';
     $field_name = 'image';
   $this->load->library('upload', $config);
    if ( ! $this->upload->do_upload($field_name))
    {
      $this->form_validation->set_message('_do_upload', $this->upload->display_errors());
      return FALSE;
      }
      else
      {
  $image_data = $this->upload->data();
     $filename = $image_data['file_name'];
     $config = array
     (
      'source_image' => $image_data['full_path'],
      'new_image' => './images/thumbs/',
      'maintain_ratio' => false,
      'width' => 300,
      'height' => 200
   );
  $this->load->library('image_lib', $config);
     $this->image_lib->resize();  
     return TRUE;
  }
}



some one help me plzzzzzzzzzzz.....
#2

[eluser]ppwalks[/eluser]
Not really getting your question
#3

[eluser]meer[/eluser]
i have to create a library of the folllowing image style files
what will be the best ????

my codes are as folllows

controller........


<?php
if(!defined('BASEPATH'))exit("NO DIRECT SCRIPTS ALLOWED ");

class Admin_controller extends CI_Controller{
function index()
{
$this->load->model('admin_model');
$data['result'] = $this->admin_model->set_admin();
$this->load->view('admin_view',$data);
}
function add_images()
{
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
$this->form_validation->set_rules('hover','hover','required');
$this->form_validation->set_rules('description','Description','required');
$this->form_validation->set_rules('image', 'Image', 'callback__do_upload');
if ($this->form_validation->run() == FALSE)
{
$this->load->view('myform1');
}
else
{
$temp=$this->upload->data();
$filename=$temp['file_name'];
$fullpath=$temp['full_path'];
$hover = $this->input->post('hover');
$description = $this->input->post('description');
$this->load->model('admin_model');
$this->admin_model->add_image($filename,$fullpath,$hover,$description);
$data = array('upload_data' => $this->upload->data());
$this->load->view('upload_success',$data);
}
}
function delete_images($id)
{
$query=$this->db->get_where('add_images', array('id'=>$id));
foreach($query->result() as $row)
{
$file_name = $row->image;
unlink("images/".$file_name);
unlink("images/thumbs/".$file_name);
}
$this->db->delete('add_images',array('id'=>$id));
redirect('admin_controller/', 'location' );
}
public function _do_upload()
{
$config['upload_path'] = './images/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '100';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$field_name = 'image';
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload($field_name))
{
$this->form_validation->set_message('_do_upload', $this->upload->display_errors());
return FALSE;
}
else
{
$image_data = $this->upload->data();
$filename = $image_data['file_name'];
$config = array
(
'source_image' => $image_data['full_path'],
'new_image' => './images/thumbs/',
'maintain_ratio' => false,
'width' => 300,
'height' => 200
);
$this->load->library('image_lib', $config);
$this->image_lib->resize();
return TRUE;
}
}
}


model........



<?php
class Admin_model extends CI_Model{
function set_admin()
{
$this->db->select('id,hover,desc,image,fullpath');
$this->db->from('add_images');
$query = $this->db->get();
if($query->num_rows()>0)
{
return $query->result();
}
else
{
return false;
}
}
function add_image($filename,$fullpath,$hover,$description)
{
$data=array('image'=>$filename,
'fullpath'=>$fullpath,
'hover'=>$hover,
'desc'=>$description
);
$this->db->insert('add_images', $data);
}
}

view......


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
&lt;html&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
&lt;title&gt;Untitled Document&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
<p>&nbsp;</p>
<p>&nbsp;</p>
&lt;form id="form1" name="form1" method="post" action=""&gt;
<p>&nbsp;</p>
<p>&nbsp;</p>
<table width="536" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><table width="536" align="center" cellpadding="0" cellspacing="0">
<tr>
<td colspan="3" align="center"><h2>ADMINISTRATION AREA</h2></td>
</tr>
<tr>
<td colspan="2" align="center"><a href="admin_controller/add_images/"><strong>ADD MORE IMAGES</strong></a></td>
</tr>
&lt;?php foreach($result as $row ) { ?&gt;
<tr>
<td width="273" height="82" align="center"><img src="&lt;?php echo base_url(); ?&gt;images/&lt;?php echo $row-&gt;image; ?&gt;" height="80" width="120" /></td>
<td width="261" align="center"><a href="admin_controller/delete_images/&lt;?php echo $row-&gt;id; ?&gt;"><strong>DELETE</strong></a></td >
</tr>
&lt;?php } ?&gt;
<tr>
<td colspan="2" align="center">~~~~~~~~~~~~~~~~~</td>
</tr>
<tr>
<td colspan="2" align="center"><a href="admin_controller/add_images/"><strong>ADD MORE IMAGES</strong></a></td>
</tr>
</table></td>
</tr>
</table>
<p>&nbsp;</p>
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;

i hope u will understand.....
#4

[eluser]InsiteFX[/eluser]
Code:
class library_name {

    private $CI;

    public function __construct()
    {
        $this->CI =& get_instance();
    }
}

// now to load a view just do this
$this->CI->load->view('view_name', $data);




Theme © iAndrew 2016 - Forum software by © MyBB