I'm writing a custom Joomla 4 component, and when I try to run python code within the Model php file to pass to the View, the exec command returns an resultValue of 2.
- The python code is valid
- The python code is executible for everyone 0755 permissions
- The webpage returns the result value of two (as per my return of $resultValue instead of result)
- The webpage of course returns nothing if I return $result instead
cat site/src/Model/WeatherModel.php
<?php
namespace Vim\Component\com_vimsjoomlaweather\Site\Model;
#error checking
error_reporting(E_ALL);
ini_set('display_errors', 1);
use Joomla\CMS\MVC\Model\BaseDatabaseModel;
class WeatherModel extends BaseDatabaseModel {
public function getWeatherData() {
exec('python ./weathermodel.py', $result, $returnValue);
return $returnValue;
}
}
cat site/src/Model/weathermodel.py
def get_weather_data():
print(['weather data in print'])
return ["weather data"]
if __name__ == '__main__':
get_weather_data()
Also, this may need it's own ask, but the manifest xml document doesn't add the necessary permissions, and I am having to add them myself after component installation.
- is
<file mode="0755">src/Model/weathermodel.py</file>
written wrong?
<folder>src</folder>
<folder>tmpl</folder>
</files>
<files folder="site/">
<filename>src/Model/weathermodel.py</filename>
<file mode="0755">src/Model/weathermodel.py</file>
</files>```