0
Welcome Guest! Login
0 items Join Now

how to better include php files ?

    • Ragdata's Avatar
    • Ragdata
    • Elite Rocketeer
    • Posts: 614
    • Thanks: 0
    • Software Engineer

    Re: how to better include php files ?

    Posted 15 years 9 months ago
    • Congratulations on finding the API - it will be your BEST friend whenever you're doing something like this.

      Your second best friend is now php.net

      $this is an object which always refers to the instance of the class which is calling the $this object. So, $this->categories is defined either in the class that is currently using it, or one of it's 'parent' classes if the current class is 'extending' another.

      For example:
       
      class myClass{
          var $category = null;
          function __construct{
              $this->category = "hello";
          }
      }
       
      $obj = new myClass;
      echo $obj->category;
       
      (would result in the output of)
       
      hello
       
      (then ...)
       
      $obj->category = "hello world";
      echo $obj->category;
       
      (now results in output of)
       
      hello world
       
      __construct is a 'magic method' (check them out at php.net) which is automatically called upon the creation of a new instance of 'myClass' - but this is not the only way for a class to define the value of a variable ... just an example.

      The best forum I could think for you to haunt would be the Joomla forums.

      If the eventlist component has an associated forum, that would probably be another good one for you to haunt - but the level of support varies greatly for 3PD components. For instance, users of DeepPockets II HATE me because I don't support it very well and usually wait for them to hit me with an email (which I may or may not answer ... most emails get my attention though).

      VERY glad you're getting into this. I hope you find it as rewarding as I have :cheesy:
    • Ragdata's Rubber Duck
      www.ragdata.net/
    • djemmers's Avatar
    • djemmers
    • Jr. Rocketeer
    • Posts: 22
    • Thanks: 0

    Re: how to better include php files ?

    Posted 15 years 8 months ago
    • Hi, here I am again,

      It is progressing and I am finding my way (slowly) in the API
      But of course I get stuck...
      more specific in the storing of an array to a row of a table.
      I understand it until the command
      in the function bind( of class JTable.

      problem is this:
      I eddited the table in mysql and added a new field country
      When I load the event, the value of country gets shown in the frontend
      but when I eddit the event, everything gets editted BUT the new field country
      I succeeded to print out the array with data that is given to the function bind()
      and there we have (piece of it)
      Array ( [title] => eventje *other fields* [country] => BE [recurrence_select] => 0 *other fields* [task] => saveevent )
      so that looks correct. Only country does not get changed.

      in bind I see this:
      foreach ($this->getProperties() as $k => $v)
      I know $k never gets the value 'country' so It cannot get stored.
      where can I set the properties?

      If you don't want me to ask things when I am stuck just say so
    • tornooi.net dutch tournament and camp sport database.
      *one fine day I'll be a joomla expert...
    • Ragdata's Avatar
    • Ragdata
    • Elite Rocketeer
    • Posts: 614
    • Thanks: 0
    • Software Engineer

    Re: how to better include php files ?

    Posted 15 years 8 months ago
    • It's fine - ask away.

      What you need to do is add your new country field as a variable of the child class of JTable that is instantiated for use with the database table in question.

      The reason that your country variable is not being saved is because the class doesn't know it exists. The "bind" function looks for incoming _POST or _GET variables matching the variable names declared in the child class that it is being inherited by. The "store" function writes those variables to the table which is declared in the constructor of the child class in question.

      Sounds like you're doing VERY well by the way ... keep at it!
    • Ragdata's Rubber Duck
      www.ragdata.net/
    • djemmers's Avatar
    • djemmers
    • Jr. Rocketeer
    • Posts: 22
    • Thanks: 0

    Re: how to better include php files ?

    Posted 15 years 8 months ago
    • tnx for the heads up :-)

      well, I thought it was something like that, your explanation confirmed my feeling.
      But I can't find a "child class fo JTable that is instantiated for use with the database table in question"

      the only thing that looks something like that is "editevent.php"
      there I find
      /**
      * Event data in Event array
      *
      * @var array
      */
      var $_event = null;

      but I never find the $_event file because I think that might be it.

      In other words: I understand what you said and was looking in that direction.
      after your explanation I have been looking again but can't find it.

      Could you give me an extra hint?
    • tornooi.net dutch tournament and camp sport database.
      *one fine day I'll be a joomla expert...
    • djemmers's Avatar
    • djemmers
    • Jr. Rocketeer
    • Posts: 22
    • Thanks: 0

    Re: how to better include php files ?

    Posted 15 years 8 months ago
    • ok after more intensive searching I found this: (finally getting vista to search in the content of php files helped a lot :twisted: )

      in editevent.php I find
      $row    = & JTable::getInstance('eventlist_events', '');
      and later on:
      //bind it to the table
              if (!$row->bind($data)) {
                  JError::raiseError( 500, $this->_db->stderr() );
                  return false;
              }
      and I know $data contains the needed new countryfield loc_country because of my added lines:
      JError::raiseWarning('SOME_ERROR_MESSAGE', 'editevent data loc_country:'.$data[loc_country]);
      JError::raiseWarning('SOME_ERROR_MESSAGE', 'editevent row title:'.$row->title);
      JError::raiseWarning('SOME_ERROR_MESSAGE', 'editevent row loc_country:'.$row->loc_country);
      wich gives as result:
      * editevent data loc_country:CU
      * editevent row title:eventje
      * editevent row loc_country:
      so in $data we have all the new information that needs to be stored
      and in $row the "old" information that needs to be overwritten.

      $row->loc_country should have the old value: "BE" that is stored in the DB...

      so the problem lies in
      $row    = & JTable::getInstance('eventlist_events', '');
      but I know I schouldn't edit the code of getInstance should I ?
      the only part of getInstance that I guess I should look into is this:
      //Make sure we are returning a DBO object
              if (array_key_exists('dbo', $config))  {
                  $db =& $config['dbo'];
              } else {
                  $db = & JFactory::getDBO();
              }
              $instance = new $tableClass($db);
              //$instance->setDBO($db);
              return $instance;
      maybe the problem is in the array_key_exists ?
      the $config? or JFactory::getDBO() ?
      but my guess is that I am on the wrong track now...

      as loc_country isn't loaded into $row from the database...
      especially I because in tha api I find
      function &getInstance( $type, $prefix = 'JTable', $config = array() )
      3 arguments
      and in editevent getInstance('eventlist_events', '') is used
      2 arguments
      so my guess is there must be another definition then the getinstance in Jtable ?
    • tornooi.net dutch tournament and camp sport database.
      *one fine day I'll be a joomla expert...
    • djemmers's Avatar
    • djemmers
    • Jr. Rocketeer
    • Posts: 22
    • Thanks: 0

    Re: how to better include php files ?

    Posted 15 years 8 months ago
    • regdata, just want to say tnx for all your help, I suddenly found this post:
      http://www.schlu.net/forum/index.php?f=18&t=6720&rb_view=viewtopic
      where everything is explained in detail!
      I don't see why I missed it in my original searching....

      I am throwing myself with renewed energy on this project!
    • tornooi.net dutch tournament and camp sport database.
      *one fine day I'll be a joomla expert...

Time to create page: 0.048 seconds