⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

can I use the imagecrud image_path dynamically with 'category'



slickdaze
  • profile picture
  • Member

Posted 21 May 2013 - 16:29 PM

hi there, I hope it's ok to ask a question about imageCRUD here..   hopefully this is quick and easy! I am trying to use imageCRUD as part of a backend for a prototype property site, and as such, I'm using the 'set relation' setting as the property id. I'd also like to be able to dynamically set the upload path depending on the property id in the url. However, I can't get it to work when I construct the variable form the url (images do not upload). When I force the upload path by simply manually setting a string, it works fine.  (although there is a red error message appearing on both, but it disappears so fast I can't see what it says) Here's some test code.



function edit($id) { 
    $this->load->model('Model_addproperty'); 
    $details = $this->Model_addproperty->get_org_user_from_property($id); 
    $path_to_images = "media/" . $details->organisation_id . "/" . $details->user_id . "/" . $id . "/img"; 
    var_dump($path_to_images); 

    $path_to_images2 = 'media/20011/3002315/294967295/img'; 
    var_dump($path_to_images2); //these two var_dumps are always identical.
    
    $image_crud = new image_CRUD(); 
    $image_crud->set_url_field('url'); 
    $image_crud->set_table('images') 
      ->set_relation_field('property_id') 
      ->set_ordering_field('priority') 
      ->set_image_path($path_to_images2); // change between 1 and 2 to test. 

    $output = $image_crud->render(); 
    $this->load->view('view_imageedit.php',$output); 
}

Any pointers gratefully received .. I think is this is something easy. Am I perhaps interfering with what the library is doing with the uri segments? Chrz.


davidoster
  • profile picture
  • Member

Posted 28 May 2013 - 07:37 AM

Hello and welcome to the forums.

Sorry for the late reply.

 

Are you certain that this line $details = $this->Model_addproperty->get_org_user_from_property($id); produces ALWAYS the desired result?

 

Can you post the code of this function?


slickdaze
  • profile picture
  • Member

Posted 03 June 2013 - 13:20 PM

Hi, thanks for reply. Yes, the function is very simple, as follows:



function get_org_user_from_property($property_id){ 
   $this->db->select('user_id, organisation_id'); 
   $query = $this->db->get_where('propertys', array('id' => $property_id)); 
   return $query->row(); 
}

When I force the image path (use $path_to_images2) everything goes well, but when I try to use the dynamic incoming url (change to $path_to_images) it goes wrong. The database gets updated, and the browser tries to load the image, but it can't find it because it didn't upload. I've attached a screenshot. You can also see the var_dumps are the same. I really think this is something silly, but I can't figure it out!

 

Many thanks.


davidoster
  • profile picture
  • Member

Posted 03 June 2013 - 21:12 PM

Well the only thing I can think of right now is that the two string are not identical and the only way this to happen is either/or :

1. some of the zeros are capital O's

2. there are some spaces or some other unprintable chars

 

Try to make an if == to see if the are really identical.

 

Also try to rename the function from edit to something else.


slickdaze
  • profile picture
  • Member

Posted 04 June 2013 - 06:11 AM

Yes, I was hoping it was something obvious but I've tried everything like that. I've now added a third string comparison, and also a check to see whether they're all identical, and you can see the result in the attachment pic. You can also see where some pictures work fine and others don't ... this is where I'm changing the code - only the fixed string works, it never works when working with an incoming segment argument. Current code is:




function edit($id) { 
$this->load->model('Model_addproperty'); 
$details = $this->Model_addproperty->get_org_user_from_property($id); 
$path_to_images = "media/" . $details->organisation_id . "/" . $details->user_id . "/" . $id . "/img"; var_dump($path_to_images); 
$path_to_images2 = 'media/20011/3002315/' . (string)$id .'/img';  
$path_to_images3 = 'media/20011/3002315/294967296/img'; 

if($path_to_images === $path_to_images2 
&& $path_to_images === $path_to_images3) 
{echo "they all seem to match";} 

$image_crud = new image_CRUD(); 
$image_crud->set_url_field('url'); 
$image_crud->set_table('images') 
->set_relation_field('property_id') 
->set_ordering_field('priority') 
->set_image_path($path_to_images3); // change between 1,2,3 to test. 

$output = $image_crud->render(); 
$this->load->view('view_imageedit.php',$output); 
}

Thanks.

 

[attachment=567:Screen Shot 2013-06-04 at 07.04.41.png]


davidoster
  • profile picture
  • Member

Posted 04 June 2013 - 09:40 AM

Shame on me that I didn't think of it before!!!

The set_path is a global path for all the photos. It's not on a per photo basis.

It holds always the last change you make!

In order to do what you're trying to, you must change the way the model of Image CRUD works!!!


slickdaze
  • profile picture
  • Member

Posted 04 June 2013 - 14:28 PM

I'm not so sure, I'm not trying to upload different images to different places from the same class instantiation.  When I test this code, I always keep the incoming $id argument the same, so $path_to_images 1, 2, & 3 are always identical.

 

Is this still not possible? Thanks for your help by the way!


davidoster
  • profile picture
  • Member

Posted 04 June 2013 - 22:10 PM

The path is not the same between different images. Is it?

Forget about it! It is! What is changing is the user id.

I have no idea then. Why don't you debug?


Sam Stha
  • profile picture
  • Member

Posted 18 September 2014 - 18:30 PM

do anyone solve this problem??


hasan37
  • profile picture
  • Member

Posted 15 April 2015 - 07:52 AM

Has anyone found a solution for this?


hasan37
  • profile picture
  • Member

Posted 15 April 2015 - 07:54 AM

This is what i have been trying.

function example1()
	{	
		$album = $this->input->get('album');
		
		$set_album = "assets/uploads/".$album;
		
		$image_crud = new image_CRUD();
		
		$image_crud->set_primary_key_field('id');
		$image_crud->set_url_field('url');
		$image_crud->set_table('example_1')
			->set_image_path($set_album);
			
		$output = $image_crud->render();
		
		$this->_example_output($output);
	}