how to make calls to the database? First time with concrete5
Permalink
Hi, it's the very first time I'm using Concrete5 and I have some questions!
I had a small database with 6 tables, which I don't know where to put now (in the database with the tables of Concrete5? Or I have to create a new database?), and I want to make calls to this database through my website (with buttons) and display the data in the website.
I'm so confused because I don't know in which file I could make this calls and how to define where to display the data.
Before using Concrete5 I just had a Nodejs, html et css files, I don't know if maybe I can move them in Concrete5 or I have to start all over.
I hope someone can help me!
Thanks in advance.
I had a small database with 6 tables, which I don't know where to put now (in the database with the tables of Concrete5? Or I have to create a new database?), and I want to make calls to this database through my website (with buttons) and display the data in the website.
I'm so confused because I don't know in which file I could make this calls and how to define where to display the data.
Before using Concrete5 I just had a Nodejs, html et css files, I don't know if maybe I can move them in Concrete5 or I have to start all over.
I hope someone can help me!
Thanks in advance.
Wow thanks a lot!
You know in which files do I have to write the calls? I though in application/config/app.php but I'm not sure at all.
You know in which files do I have to write the calls? I though in application/config/app.php but I'm not sure at all.
It should be in `/appilication/config/database.php`. It stated on the top of the section `Another database`.
You can either move your tables into the same database as concrete5, or add a connection to an external database from concrete5.
https://documentation.concrete5.org/developers/framework/database-ma...
For actually querying your data and displaying it, for an on-page view develop a simple block type to do so. Addons such as Block Designer can help you get started if creating a block from scratch is too big a step. https://www.concrete5.org/marketplace/addons/block-designer...
If you are only displaying data, rather than developing blocks you could consider my Universal Content Puller addon to pull data from your tables or external database. https://c5magic.co.uk/addons/universal-content-puller/example-site-d...
https://documentation.concrete5.org/developers/framework/database-ma...
For actually querying your data and displaying it, for an on-page view develop a simple block type to do so. Addons such as Block Designer can help you get started if creating a block from scratch is too big a step. https://www.concrete5.org/marketplace/addons/block-designer...
If you are only displaying data, rather than developing blocks you could consider my Universal Content Puller addon to pull data from your tables or external database. https://c5magic.co.uk/addons/universal-content-puller/example-site-d...
Hi! Thanks a lot for the help!
Since I'm doing a website for a school project, unfortunately I can't use the addons. So I'm trying to figure out how to make the query in a block type.
I'm a little bit stuck and I hope I can ask you some clarifications... I understand the structure of a block type but I don't get in which file I have to put the call to the database and the query, and also how to ultimately pass this information to the view.php. I tried different locations but always without results.
Hope I'm not asking much, thanks a lot in advance!
Since I'm doing a website for a school project, unfortunately I can't use the addons. So I'm trying to figure out how to make the query in a block type.
I'm a little bit stuck and I hope I can ask you some clarifications... I understand the structure of a block type but I don't get in which file I have to put the call to the database and the query, and also how to ultimately pass this information to the view.php. I tried different locations but always without results.
Hope I'm not asking much, thanks a lot in advance!
Look through code in some of the core blocks. There are many examples. Also look through some of the free addons in the marketplace and on GitHub.
Generally, query the db in the block controller view() method, then call $this->set('name', $results); to pass data to the view.php file.
There is also plenty more relating to making blocks in @shahroq's cheat sheet.
Generally, query the db in the block controller view() method, then call $this->set('name', $results); to pass data to the view.php file.
There is also plenty more relating to making blocks in @shahroq's cheat sheet.
Hi! I tried to make a query in a block type and it worked, thanks a lot!
Now I'm trying to do one with a variable from the edit page (in the picture is $titre_projet), but when I do this it doesn't work. I think the form.php doesn't send the variable to the other files, and I can't find any help, I hope you can help me again this time!
Sorry to bother you again, thanks again in advance! :)
Now I'm trying to do one with a variable from the edit page (in the picture is $titre_projet), but when I do this it doesn't work. I think the form.php doesn't send the variable to the other files, and I can't find any help, I hope you can help me again this time!
Sorry to bother you again, thanks again in advance! :)
Your inputs are passed to the controller through the $request object when you save the edit form. More about that in the concrete5 docs on developing new block types. However, that is for editing the block, not for managing data, so perhaps you are on a wrong tangent.
I used the block type Hello World that is downloadable in the concrete5 documentation as a model to do my block.
In the Hello World block they don't use any special request to "send" the variables from form.php to controller.php and view.php, this is why I'm confused!
I just did the exact same thing and it doesn't work, do I need do add something?
In the Hello World block they don't use any special request to "send" the variables from form.php to controller.php and view.php, this is why I'm confused!
I just did the exact same thing and it doesn't work, do I need do add something?
look at $data in the save() method of the controller
https://github.com/shahroq/whale_c5_cheat_sheet#database-1...