Giter Site home page Giter Site logo

Comments (10)

mychidarko avatar mychidarko commented on May 20, 2024

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.

mychidarko avatar mychidarko commented on May 20, 2024

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.

wfsdaj avatar wfsdaj commented on May 20, 2024

@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.

mychidarko avatar mychidarko commented on May 20, 2024

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.

wfsdaj avatar wfsdaj commented on May 20, 2024

Yes, there are still errors. 😅

from leaf.

mychidarko avatar mychidarko commented on May 20, 2024

Can you confirm something for me? Do you have a .env file in your setup?

from leaf.

wfsdaj avatar wfsdaj commented on May 20, 2024

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.

mychidarko avatar mychidarko commented on May 20, 2024

And are you correctly loading the .env variables into your code?

from leaf.

wfsdaj avatar wfsdaj commented on May 20, 2024

I thought the .env file was automatically loaded just like laravel。
How can I load .env file correctly? require vlucas/phpdotenv?

from leaf.

mychidarko avatar mychidarko commented on May 20, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.