MVC/ OO events system

Asked

Viewed 129 times

-1

I’m writing my first PHP application. What I have been studying, I have chosen to learn Object Orientation and MVC.

I’m building this application by following a book I have, and it’s returning the following error:

Parse error: syntax error, unexpected 'private' (T_PRIVATE) in C:\wamp\www\denis-manzetti\sys\class\class.calendar.inc.php on line 11

sys/core/
init.inc.php

sys/config
db-cred.inc.php
class.event.inc.php

sys/class
class.event.inc.php
class.db_connect.inc.php
class.calendar.inc.php
public/
index php.

if anyone can quote what I should study, I thank you in advance, hugs

  • Fix the line 11 of the cited file: public function __construct( ... ){ private function _loadEventData( ... ) } }. You put the method _loadEventData within the __Construct.

  • Notice: Undefined variable: db in C:\wamp\www\denis-manzetti\sys\class\class.db_connect.inc.php on line 7

  • db_connect.inc.php line 7: protected function __construct( $dbo=NULL ){ if(is_object($db)) [...], you defined $dbo and used $db.

1 answer

3

You are setting an attribute public and within this attribute, is setting another attribute which is the private, this cannot happen, you cannot define an attribute for a function and within it create another function with another attribute. I don’t know how it is in your book, but normally this generates this error, what you can do is create a function without attributes, like function, if you’re inside a function that already has an assignment. You can see the compilation on ideone:

https://ideone.com/P1m7Nu //Code that generates the error

https://ideone.com/EiPIQU //Code that does not generate error

But the correct method of doing this algorithm of yours is to separate the _loadEventData the construction method, and call it through the operator $this being as follows:

class Calendar{
    private $_useDate;
    private $_m;
    private $_y;
    private $_daysInMonth;
    private $_startDay;

    private function _loadEventData($id=NULL)
    {
       //codigo
    }

    public function __construct($dbo=NULL, $_useDate=NULL)
    {
        $this->_loadEventData();
        //codigo
    }

}
  • Give me an OOP example of how you invoke _loadEventData.

  • https://ideone.com/mW0tnz

  • 2

    Now yes :) Use this last comment as an answer, because it is OOP and brings light to the AP, and put the code here - don’t just trust external link.

  • 1

    Later with time I will update ;)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.