Comments (10)
Hi @wfsdaj, thanks for trying out Leaf. First of all, can you give me some information on your setup? Are you using Leaf on it's own or something like Leaf MVC/Leaf API?
from leaf.
Also, Leaf Models run on eloquent, and not Leaf DB
, that may be one of the reasons you're encountering this problem, but I can't say so just yet, which is why I need a more information on your setup
from leaf.
@mr-phlames thank you for your reply. I use Leaf. I can use the db class normally on the index page.
leaf/index.php
require __DIR__ . "/vendor/autoload.php";
$app = new Leaf\App();
require __DIR__ . "/config/app.php";
require __DIR__ . "/app/routes.php";
$users = $db->select("users", "id, name")->fetchObj();
echo $users->id; //output 1
$app->run();
from leaf.
Yes the DB class just provides a simple way to use your database. Something you can work with anywhere in your code without worrying about models and stuff like that. So in that case, is you problem resolved or do you still have issues with the database?
from leaf.
Yes, there are still errors. 😅
from leaf.
Can you confirm something for me? Do you have a .env
file in your setup?
from leaf.
my /.env file
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=demo
DB_USERNAME=root
DB_PASSWORD=root
my /config/app.php
$app->config([
'mode' => 'development',
'debug' => true,
'templates.path' => './views',
'log.enabled' => true,
'cookies.path' => '/',
'cookies.encrypt' => true,
'cookies.lifetime' => '20 minutes',
]);
from leaf.
And are you correctly loading the .env
variables into your code?
from leaf.
I thought the .env file was automatically loaded just like laravel。
How can I load .env file correctly? require vlucas/phpdotenv?
from leaf.
Yeah, that should be the easiest way.
Env files are loaded automatically only if you use something like leaf MVC or leaf API.
from leaf.
Related Issues (20)
- URL params in POST request has bug. HOT 2
- Boilerplate: Leaf with the Hexagonal Architecture pattern and Domain-Driven Design HOT 1
- Default project generated by `leaf create` does not work due to missing leafs/cookie HOT 1
- Middleware route option not working in group HOT 2
- Authenticating API routes in leaf framework HOT 7
- I can't seem to get the 'app.down' config to be acknowledged. HOT 5
- Basic template doesn't work HOT 14
- Cannot generate tests on windows HOT 1
- RoadRunner or Swoole support? HOT 3
- request problem HOT 2
- LeafPHP MVC Error: Vite manifest not found at: /build/build/manifest.json, when trying to run with build in production mode HOT 5
- How to auth using email or another column
- Queue command "config" and "install" not available. HOT 2
- How to add middleware in this route app()->resource('/posts', 'PostsController'); HOT 3
- register with json return false
- Leaf MVC: `assets()` function behaves differently and breaks in production HOT 1
- MVC setup for production getting Vite manifest not found at: /build/build/manifest.json HOT 2
- Enhanced Route Handler Definition Flexibility
- Leaf development status
- SQL Join, and database model in leaf/database
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from leaf.