We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Data is not returned using Volt. Possibly permission issue.

I am using Amazon linux instance. i have setup apache to be in the group file ownership. I setup app/cache to have 777 permissions. It seems to be working good until the moment when my controller returns data from Model to View via Volt:

    foreach($events as $event){

            $data[] = array(
                                'title' => $event->event_time,
                                'start' => $event->start_date,
                                'url' => UPDATE_URL . $event->appointment_id
            );
        }
            $eventData = json_encode($data, JSON_NUMERIC_CHECK);

            //Sending json to View
            $this->view->setVar('data', $eventData);

data variable returns nothing in the index.php file, even though DB is full of events. Checked cached volt file, i can see <?php echo $data;?> Even though when i load index.php has no events. This code works just fine on my Lamp locally on Windows. DB works fine, i was able to login using the user created in db.

I think i can still miss some permissions that need to be corrected.

Please advise, maybe i need to switch off caching?



14.8k
edited May '16

tried to return just numbers

    $this->view->setVar('data', 123);

It did not help. Nothing on the page. That's why i think it's not related to getting data from db.

Which PhalconPHP version are you running? Phalcon 2.0.11 or below?



14.8k

today cloned from Github, i think the most recent one



14.8k
edited May '16

PHP Notice: Undefined variable: data in /var/www/html/booker/app/cache/_var_www_html_booker_app_views_calendar_index.volt.php on line 44, referer: https://.../booker/session/end

APACHE Error log



14.8k

phalcon version is 2.0.12



14.8k

on my local windows ver 2.0.9.

What php version you are using?



14.8k

PHP 5.6.21 (cli) (built: May 2 2016 23:27:53)



11.6k

you should not set 777 on your web folder, that's mean that anyone can w/r/x yours files...not so good so using 777 is not your problem Set the folders permissions to something more restrictive and case by case. First see the log of your database (/var/log/...) using tail ( tail -f /var/log/yourfile.log ) as your are using your app in browser, do the same with server log (for apache /var/log/apache2/error.log (another debian package is called multitail, and allow monitoring of more than one file at a time)



14.8k

i set permissions back to 755 on cache folder. DB log shows the following:

InnoDB: Creating foreign key constraint system tables
InnoDB: Foreign key constraint system tables created
160516 17:14:55  InnoDB: Waiting for the background threads to start
160516 17:14:56 InnoDB: 5.5.46 started; log sequence number 0
160516 17:14:56 [Note] Server hostname (bind-address): '0.0.0.0'; port: 3306
160516 17:14:56 [Note]   - '0.0.0.0' resolves to '0.0.0.0';
160516 17:14:56 [Note] Server socket created on IP: '0.0.0.0'.
160516 17:14:56 [Note] Event Scheduler: Loaded 0 events
160516 17:14:56 [Note] /usr/libexec/mysql55/mysqld: ready for connections.
Version: '5.5.46'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  MySQL Community Server (GPL)

apache server log i provided above, which returns error that data variable that i am sending from Controller into view, is not defined. which is strange behaviour as it works fine on my local windows phalcon installation.

Post your routes.



14.8k

Are the PHP versions different? PHP 5.6.21 on linux and 5.6.15 on my windows machine



14.8k

do you mean app/config/routes.php?



11.6k
Accepted
answer
edited May '16

Except if your DB log is not set to an enough verbose mode (see here: https://dev.mysql.com/doc/refman/5.7/en/binary-log-setting.html ), no connection attemps are logged here (just init procedure)...Your log (set at "statement level") should show each query from your controller (if you don't use caching)...

your php log saying $var is not defined let suppose that the query was first not done correctly (or not done), does "php -m" confirm that phalcon and DB related modules are loaded (do a check adding "phpinfo();" in your index php too, sometime the php cli version is not the same that the one apache use)



11.6k

if volt file in cache is generated, that's means that controller have been reached, no?

do you mean app/config/routes.php?



14.8k

Thnx goes to graphmatic!!! DB issue!!! Enabled general query and found the problematic query. Executed the query in phpmyAdmin which showed me that i refer to one of my tables with capitalized name, which worked fine on my Windows machine where i have Xampp and you can refer to tables both with capitalized names and lowercase(my case). This is not so on linux instance where i am hosting my app right now.

I added getSource method to my model class where i return lowecase name of my table. Issue is fixed. Thank you everybody and especially graphmatic

Another one with using Windows. Windows should be prohibited for developers. :)