Question about class instantiation

Sorry if this is in the wrong group.  The drop down select is showing only numbers on my ipad. 

 

I recently encountered a couple of  things and wondered if anyone has any insight that can help understand if this is normal in elgg.

1st question :  I created the class for my main object in my announcement plugin. My preference in classes is to have the class coded to set up some of the properties when it instantiates .  In this case i had it  setting the access to public and the subtype.  It all seemed to work, the entities saved and  looked correct in the database, 
in testing i created several objects Using my form  and it saved them to the database.  Then i moved on to creating the view. Idiscovered that the  call to get the entity created an empty object. An SQL query in phpmyadmin did  pull up a record from the database using the relevant guid.
 

When i tried to pull up  any of my Announcement  entities in entity explorer i received a fatal error. The error referred to relationships, which i did  not have at the time. 
 

After several curse words i moved the code to set the access to public and the subtype to the action file and all is well.  
 

I have  scratched my head near bald trying to see why this would cause a problem.  Anyone have any insight?

My second question involves my attempt to extend the  ElggFile class.  I could not find an example of this being done but i can tell you it didn’t  work as i tried it. Wondering if anyone has done this or seen it done anywhere?

 

 

  • Thanks. This one or one like it is what I used as a model.  The file class was being created as expected. That is to say,  I could save it to the database I could be read using entity explorer.  To demonstrate 

    the following code 

    $lrg = new ElggFile();
    
        $lrg->setFilename("lrg/" . $filename );
    
        $lrg->open('write');
    
        $lrg->close();
    
        $lrg->access_id = ACCESS_PUBLIC;
    
        $lrgpid = $lrg->save();  // save as entity 
    
        $lrgdest = $lrg->getFilenameOnFilestore();
    
      $is_lrg = elgg_save_resized_image($sourcefile,$lrgdest, $lrgparams  );
    
    

    Works but when I   substituted my class in instead of EllgFile  it threw errors in the symfonly libraries 

  • I don't see what could explain the fatal error in the entity explorer. Could you maybe tell a bit more about the exception?

    I did not see what caused it either.  As I mentioned the database entries looked fine and a SQL query pulled things as expected. I discovered the problem when I tried to pull the entity for a view. the view was creating a blank object for all objects of the custom class type.  The class was (is) registered in elgg-plugin.php.  The same view could pull any other object as expected. The entity explore did not give a lot of info in the error *well not a lot of useful info)  It essentially said the object was empty. 

    I took the two lines from the initialize attributes function and put them in the action and from that point, all object created using the same class work as expected.   


        

  • RvR  

    //If you'll insult me (and you're doing it now), you'll be banned here.//  

    You are right and I am sorry I came in hot. Yes I should have included code but I was posting from my iPad away from my development box, Also I had already deleted/changed the code to make the project work and was simply hoping for some general ideas as to why a class might cause such errors so didn't think code was relevant. My bad

     I will make sure to include code in future posts. 

    I was wrong in my statements to you and I really do appreciate your efforts. that said please try to remember that not all of us are at your level. This is a beginner forum. It is not alwasy easy to ask for help and being told the RTFM and figure it out ourselves is not what we are hoping for.  

  • I did not see what caused it either.  As I mentioned the database entries looked fine and a SQL query pulled things as expected. I discovered the problem when I tried to pull the entity for a view. the view was creating a blank object for all objects of the custom class type.  The class was (is) registered in elgg-plugin.php.  The same view could pull any other object as expected. The entity explore did not give a lot of info in the error *well not a lot of useful info)  It essentially said the object was empty. 
     

    So if you did :

    var_dump(get_entity($guid_of_your_custom_class));

    Does it result in YourCustomClass or in an ElggObject? If it's an ElggObject than your class registration is wrong (it should still be able to show all information stored in the database for this object however).

    Works but when I   substituted my class in instead of EllgFile  it threw errors in the symfonly libraries 

    without seeing a backtrace of the errors, it's hard for me to guess what happened.

    Like i said all looks fine, there must be one (dumb/stupid) thing that is wrong. But finding that one thing is almost always the hardest part ;)

Beginning Developers

Beginning Developers

This space is for newcomers, who wish to build a new plugin or to customize an existing one to their liking