I use a headless drupal to expose an api for my front app and I have a question regarding the creation and update process of entities in Drupal.
It could be usefull if I could create my entities and my bundles programmatically like writing a php script and run it. And maybe other to alter my sql schemes and entites fields.
I am actually quite noob with drupal (I am used to django and migrations files that works exactly like that). And I want to know of there is an equivalent for it with drupal (7 or 8 ^^).
You can definitely do this in Drupal using the Entity API. I've only dabbled with this in D7, but it does exactly what you want. Of course, it is all done using a Drupal module in hooks, not just a standalone PHP script.
You create your table using hook_schema, and then handle schema migrations using hook_update_N (where N is any number you choose). The entities are defined using hook_entity_info Then you need controllers to manage your entities, fields and field instances that tell Drupal how your entities relate and some information about display.
It is a fairly involved process the first time you run through it. I know it is bad form to link to external resources here, but this subject is fairly dense. I found http://www.zyxware.com/articles/4779/drupal-how-to-create-custom-entity-programatically-in-drupal-7 to be a very valuable resource when I was creating a proof of concept for a project here at work.
Good luck, and let me know how it goes.
If you are using Drupal 8, Drupal Console will help you a great deal. There is a command for generating entities, controllers, forms and many other things.
For Drupal 7 the Entity Construction Kit is the way to go
I have used both these tools sucessfully in production.
There is a lot of boilerplate code to write as you might have noticed from Quint's suggestion.
Related
Thanks in advance.
Learning Drupal right now as recommended by many people and I cannot get a straight answer to this question:
What are the steps to setting up a CRUD application using Drupal?
(I'll explain further. But that is the premise.)
Working on an application that will do reporting and help out a small sales company with their prospecting and data analysis. Excel right? nope. Their clients will also be needing to access some of their data live via a webapp, so there will need to be different logins with levels of access (clients will see specific data related to their account, sales people will see their accounts, and management will see everything). Here's the real kicker they would like to eventually make it into a native app for android or IOS.
Originally I was going to build it in Codeigniter... which seemed easier, but it was recommended to me that I could cut down on my workload and utilized the "services" module later to do what I am looking to get done now and in the future.
Ignoring the project, I haven't even been able to figure out how to create a form for inputing data (I was assuming "Webforms"). Have that stored to a database, and then displayed in a sortable table.
I have searched around and can't really find a guide to building a simple CRUD application using Drupal as a CMS. I am totally willing to figure out how to put it together if someone could just tell me what modules/ things I need to do.
Example (INCORRECT)
1) Install these modules: Webform, views, CCK, Webform MySQL Views)
2) Activate the modules
3) Configure _ to interact with a specific database Table
4) Et Cetera
In all fairness, I'm still learning how to use Drupal and Doing CRUD (Create, Read, Update, Delete) type interactions might now be possible. If it isn't possible then I apologize for your reading all the way down.
Cheers + Happy Summer
Make sure you're using Drupal 7 (which has CCK built in). Then create one or more content types for the things people will see. Install Views and use that to build the displays for each role (Views is pretty powerful). You'll need to research which node access module would help you best restrict add/edit/delete privileges.
However, you said CodeIgniter is an option (ignoring the fact that CI is not maintained anymore). Any reason why Drupal was recommended instead of another PHP framework like Silex/Yii/Symfony/ZF2/LAravel? Depending on client needs (and how flexible they are) you may find yourself fighting against how Drupal wants to do certain things. If they eventually want to power more than a website via an API, seems like a non-Drupal solution could be better fit. (Until Drupal 8 is out and changes things up a bit)
This is what I have:
An entity-relational schema, modelled for Doctrine 2.0 (in PHP);
The generated database, on a MySQL server.
This is what I want:
A very basic CRUD web-interface to the database, that allows me to (you guessed it!) create, read, update and delete records, with extra credit for implementing CRUD operations on entities and relations instead of records.
Now, I'm terrible at writing web applications myself (read: I'm lazy). Are there any options to generate a CRUD web application from a MySQL database, or from a set of Doctrine entities?
I'd be willing to stop using PHP (and thus rewrite the entities for JPA, Ruby ActiveRecord, etc...) but not MySQL.
I see a lot of similar questions: however, most of these questions have answers that give CRUD operations for in PHP code, or recommend using Doctrine.
An answer such as "There is no such tool, stop being lazy" would also be appreciated.
You should have a look at Grocery CRUD.
Really simple, easy to use /deploy and neat UI.
http://www.web-and-development.com/grocery_crud/
I did a complete web CRUD of my DB in a couple of hours (including additional PHP webservices) Amazing :-)
Symfony does this (at least the 1.x series I am used to). I should think version 2.0 also does, under either Doctrine or Propel (and both of those will work with MySQL).
CakePHP (user guide) takes a database model and generates controllers that do basic CRUD operations for all of your tables. It also includes views and a basic stylesheet.
If your hosting setup can handle Python, the web2py framework offers instant CRUD for a database and a very user friendly (and laziness-friendly) online dev environment. I don't think it's designed to be laid overtop of an existing database, but you can import a CSV file with your database contents. http://www.web2py.com
One of the great things about web2py is that creating custom (public) CRUD pages is also dead easy. In a controller file it's as easy as
form = CRUD.create(db.myTable)
return dict(form = form)
Then in a view file you just add
{{=form}}
And that's it! All of the form creation, input validation, etc., is handled for you. I should also add that the data abstraction layer in web2py is very easy to learn and meshes with mySQL easily. One great thing about it is that web2py performs on-the-fly changes to your datastructure or even migrations from one DB back-end to another.
Not every hosting company knows how to support web2py, but it's easy to deploy on the Google App Engine or with a company like Fluxflex.com
I've been looking for a drop-in admin panel like this too, so far I've 3:
AjaxCrud - http://ajaxcrud.com/
Peek from Code Canyon - http://bit.ly/toKKrB
SQLBuddy - http://www.sqlbuddy.com/
Love to hear any other suggestions!
Ruby on Rails' "Scaffolding" should be exactly what you're looking for...
As according to this answer, I've tried Xataface, which gave me as decent a result as CakePHP or Web2Py would have given me. Am now trying Symfony 2.0 (which is a lot harder then I'd have expected) for the extra credit.
I'm trying to convert site www.mircscripts.org to Drupal, and researching more and more about migration I've been getting more and more confused.
There are various modules that supposidly will help with the migration process, but these are nothing but confusing and all lack in either a. documentation (listen up Migrate module!) or b. only support Drupal 6.
The Migration Module you seem to have to dive into PHP code and create some "mappings" to your old table data and Drupal. First off, I would ideally like a GUI (Table Wizard only supports Drupal 6 it seems, and the superseded Data module only Drupal 6 too). I also want to import data into Drupal and not use "mappings." I want to be able to disable the Migrate module after all the data has been "converted" to be Drupal node compatible.
If you take a look at the site above, you can pretty much see the scale of data, forum, comments, etc and get an idea of how the database tables look, just your usual stuff; users, comments, and more custom stuff like "files" which stores all the different scripts uploaded by users.
Any suggestions on how I would I go about converting the site?
Cheers
Gary
edit: I forgot to mention the site is almost entirely custom made. The code for it looks like my nan on her way to bingo -- a complete mess. There is an interesting bit of code available at http://drupal.org/node/261066 if you scroll down, although I don't feel like doing node_save() 60,000 times for every record, for just one table. It sounds evil.
The migration module comes with an example migration module and some documentation to facilitate content migrations. Dozens of sites have utilized this to achieve migration. It is not a GUI point and click but very flexible and can be tested repeatedly.
I've written my own modules before to do custom migrations prior to this, and its not as bad as it sounds. You just need to know how the schema relates and map it on paper, then pseudocode and test.
For www.dogfish.com, I migrated 12,000 some nodes. For a band site I am trying to relaunch, I have migrated 75,000+ nodes. Both methods I utilized a db connection and cron to get the next X results. I could have also used BatchAPI but that seemed slower.
Migrate module is the way to go.
Take a look at feeds. It's a GUI importer thing that allows you to map fields in a file to objects like nodes.
http://drupal.org/project/feeds
There's nothing evil about node_save over all the rows in your table. That's essentially what any import module should do anyway. I worked on a huge d5 project where we imported millions of nodes that way. It works fine.
Some people have recommended saving to the database directly. Never do that. It's just not the right way to create nodes. Use the Drupal API!
As i have spent years on drupal. I did not see any full fledged module for migration. Its better you start coding, it will save time and that the smart idea :)
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I know ASP.NET C# very well. I make a lot of stuff like surveys and custom web applications.
I'm having a lot of trouble wrapping my head around Drupal and figuring out how to do 'special' programmatic things, like searching a list of clients, or creating a web application.
1 - I've been reading books and drupal API but I'm still having a lot of trouble getting started with anything at all. Where does custom code go in respect to pages, modules, snippets...? How do I replicate form X that I did in ASP.NET into a new page in drupal? Etc. It is super hard to wrap my head around Drupal, it seems so large and easy and extensible yet also like it is difficult for me to code. What can you recommend for an ASP.NET application programmer to learn to work with/in Drupal?
2 - Sometimes we write complete ASP.NET applications for clients, and these applications are not indended for clients to go editing them. For example, we will have our entire website in drupal, but inside of that website we will have a place for users to use a special search for database information. We don't want simple website editors and content providers trying to edit this specially coded page(s). How do I handle not wanting clients to edit anything in a Drupal application? Is it handled via page/user permissions? Is the best thing to develop and host an application completely outside of drupal? Is the drupal application it's own drupal instance inside of a drupal website (nested drupals?) ?
3 - Lastly, how do I handle databases? I understand Drupal and PHP are set to work best with MySQL. We have MS SQL databases that are used by multiple applications and would like to use them for new applications as we start using Drupal. For example, we have a Staff directory that feeds ASP.NET reporting application, ASP.NET Staff Listing application, and want to make a new Drupal PHP application that also uses (and perhaps inserts/updates more information into) that database. What is the best/easiest way to handle MS SQL databases and/or MySQL databases being used and updated by multiple Drupal and ASP.NET applications? Would it be easier to have all the applications use the MS SQL databases, or maybe to replicate the databases on MySQL for the Drupal/PHP apps and somehow sync the two databases?
I hope it is alright if I ask multiple related questions in a single post.
I'm afraid that I don't have any experience with Drupal so I can't offer any insights into your first or second questions, but on the third question:
What is the best/easiest way to handle
MS SQL databases and/or MySQL
databases being used and updated by
multiple Drupal and ASP.NET
applications?
If you are going to perform CRUD operations from both your ASP.NET applications and your PHP/Drupal applications, then I would recommend against trying to sync data back and forth between MySQL and MSSQL since this will cause latency problems plus you'll then have to deal with the differences between the two database management systems.
Instead, I would recommend that you look at using stored procedures to control all database accesses. This way you can ensure that all of your database CRUD operations conform to same rules and logic.
Using MSSQL in both ASP.NET and PHP shouldn't be a problem, especially not with the very excellent PDO library that provides a standard interface for accessing a number of popular database management systems. It should allow you to quickly and easily connect with and begin using your MSSQL databases within your PHP applications.
It is some good questions you ask. I'll try to answer them to the best of my ability. I haven't any experience with c# of APS.NET, so I don't know exactly where you are coming from. I myself learned Drupal as an inexperienced python/django developer. So in some ways I can understand some of the troubles you are going through trying to learn Drupal. Some of these things will simply require time/experience/experimenting before it will go away.
To really understand Drupal and the Drupal API you will first need a good understanding of PHP. Sometimes Drupal do some complex PHP things, so if you don't understand the syntax or the PHP functions etc, you can easy get lost.
Where do code live?
Drupal is built as a moduler system. Drupal itself is a set of modules, some of which are required for Drupal to work properly. If you want make some custom code, that is you want to do something, that you can't use a module for. There are about 5000 modules developed for Drupal. Often even when being a skilled programmer, the best choice is to find a module that will do what you need or can get you where close. So what you do, it to create a module of your own.
Make a folder with the name of the module
Create a modulename.info inside it which holds some info about the module formatted in a special way. Drupal will need it to fx display the module on the module list page where you activate modules.
Lastly create a modulename.module file where the core of your code for the module will be.
Another thing that is important to understand with Drupal, is that it uses a hook based system. Hooks are like events that fire once certain things happen that you want to hook into and either alter the flow, or do some things of your own. Fx you could record every time a specific form was displayed, or you could alter the form, adding/removing fields.
Forms
Drupal has a FAIP or Form API, that is uses to generate form, this is something that has it's own page in the documentation. The idea is that you create an associative PHP array which holds information about each element of the form, and Drupal will use that to create the form.
Books
There are a lot of good books for Drupal that you can learn from. The book I myself have learned the most from is Pro Drupal Development
First of all, Drupal has a very fine grained role based permission system, that will allow you to setup exactly what your clients are allowed to do. You can create different roles, like moderator, content creator, admin, sysadmin ect, and give different permissions to each role. This is pretty easy and is setup within the Drupal AI. However, you will need to know the permissions as some are super permissions that will give access to a lot of things. Now for integrating your applications, that is something that you probably want to write a custom module for. I don't know exactly how you want to do this. But I think the best result would be gotten by letting Drupal create the pages, forms etc from your application and just send data back and forth. That way the theme = layout of the site would be consistent. That way users wouldn't get the feeling that they left the site, but this simply was yet another feature the site offered.
Drupal is not just set to handle MYSQL best, You will actually need either MYSQL or PSQL as your drupal database backend. The reason is the way Drupal handles queries, that allow you to write non specific queries that will work, no matter on which of the two types you use, or if your tables has a prefix. So for all of the Drupal internals you will need one of the two. PHP can connect to MSSQL and run queries against that database, so you could without much problems write custom code that run queries to your other application's databases and either fetch or update data. Depending on the data, you might want to create a table in your database that you can read and write to, and then sync the databases when needed. It depends a bit on your use case. I have done the latter, in the case where I didn't need to write to the database, but only needed to fetch some product information form a legacy database that was still being used by other systems.
First of all, I think what's important to understand Drupal's limitations, there are things it's not really made for. It's sort of a web application framework but if you're doing a lot of custom work with your own custom datamodelling and stuff, Drupal might not be the most flexible or easily implementable solution to your kinds of problems. A more general framework like for instance Zend Framework might be more suited.
An important lesson in learning Drupal is: don't hack core or other modules. This will make upgrading core or modules very time-consuming. Instead "do like Drupal" and override using hooks. In theming you can also override with hooks, but also in other ways. Overriding is powerful so understand that concept well.
I'd say, pick a way of learning that is your style, screencasts, IRC, hacking, user meetups IRL, books, articles or any combination and look for material on Drupal. Just start mucking around and get a feeling and understanding of how Drupal works. Understanding the jargon is an important part, so what are: nodes, blocks, regions, hooks, modules, themes.
Drupal has a very flexible permission system, and it's probably the best choice to use that instead of making your own. You can write your own modules that add to or alter the behavior of Drupal. So if you want to write a new application that works with Drupal you can write a module performing the functionality the application has to have and make use of all the facilities Drupal offers, including users, the permission system, etc, etc. I don't really understand the last part of your second question "Is the drupal application it's own drupal instance inside of a drupal website (nested drupals?) ?". Drupal is a collection of PHP files on a server that, together with a slew of tables in a database serves request made to it. Multiple Drupal websites (so different PHP files) can reference the same database or parts of it (for example the user table). There's not really an "instance" of a Drupal site, as there's not really an "application". I could of course be too unfamiliar with these terms but I don't think PHP works with "instances" of "applications".
That's a hard problem, afaik Drupal doesn't work with MS SQL, so any connections in that direction you might have to make yourself. I'd also ask around the Drupal forums or on IRC.
Good luck!
rlb,
I've done quite a bit of Drupal and have strong ASP.NET experience. You really need to read up to get your mindset straight. They use layers in an MVC-like fashion that is very foreign to WebForms & ASP.NET MVC developers ... and quite frankly at first seems odd.
Here's a list of things I did to get really, really good quickly:
Get a host like at hostgator for $8 which will let you install Drupal
Get the book Pro Drupal Development for Beginners ... excellent and really covers a lot of areas http://www.amazon.com/Pro-Drupal-Development-Second-Beginning/dp/1430209895/ref=sr_1_2?ie=UTF8&s=books&qid=1257545528&sr=8-2
Get on the Drupal forums
Be ready to contribute. Drupal has a lot of features, but in the end the best way is to be someone who contributes code back
There are a number of IDEs to consider, but to start a text editor should be fine.
Good luck.
Some good answers here, so I'll just fill in some brief items.
1 - Learning Drupal: Pro Drupal Development is the best book for this. Getting into the issue queues and interacting with developers is a way to get familiar with specifics. Your question about forms relates to how Drupal handles forms. The FAPI is pretty robust in Drupal, and protects you from security gaffes. Also api dot Drupal dot org is where the code is documented, though there are docs elsewhere. Google is your friend. (On the Drupal site itself, use the native search to get faceted results.)
2 - This is a user permissions issue. You can limit creation and editing permissions based on content type. For access control (read), you will want to use one of the many modules for access control. It really depends upon your use case.
3 - Drupal has the most community support for MySQL, but people run Drupal on MS SQL as well. In Drupal 7, you will likely see much more support for non-MySQL as this release introduces database abstraction.
Probably the worst thing to do is hack around the margins. It really pays to learn the ins and outs of the Drupal basics -- administration and coding -- so that you can truly leverage the power Drupal brings to the table.
And if you're hunting for modules, http://drupalmodules.com is your friend. ;)
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 4 years ago.
Improve this question
I have to make some database requests with PHP on a MySQL database.
Question : What is the best (simpliest) framework to get thing done right CRUD (Create Read Update Delete)?
I also have to populate the database, what is a good tool to do that. The only one I know is SqlMyAdmin, wich does not look good. An online tool would be great.
Your experience is valuable: tell me what do you use and why ?
I have taken a look at CodeIgniter, looks nice, what do you think... overkill ?
For lots of operations (especially CRUD, which work out of the box once you've written the schema files), the ORM Framework Doctrine is really great.
If you want to go farther than just DB access, you might take a look at the PHP FRamework symfony, which provides an admin generator (there is even a screencast about that one).
(And has great documentation, such as the jobeet tutorial)
(BTW, symfony uses Doctrine as ORM ^^ )
But maybe it's a bit overkill (and requires a too big learning curve) if you need something simple...
To load data to MySQL, what about LOAD DATA INFILE, which (quote from the docs) "reads rows from a text file into a table at a very high speed".
I recommend GroceryCRUD because of the good engineering and documentation
Copy files into your web folder
Configure MySQL database
Specify MySQL table name
=> You get a paginated JqueryUI table with create/edit/delete buttons.
create/edit opens a form page based on the MySQL table schema. For example, a boolean, a varchar and a text get turned into a form with active/inactive radio buttons, a text field and a wysiwyg html editor.
Note: GroceryCRUD is built on CodeIgniter so you will have a copy living in your admin directory. You don't have to use it for building your main site.
Security Advisory: Any library can have undiscovered security vulnerabilities, so it is recommended to minimize exposure by protecting your copy of GroceryCRUD with BaseAuth and permitting SSL access only.
I'd second Pascal's comment re Symfony (I would uprate but not enough credit :-() - Symfony has a great admin generator, and once you get your head around the app->module->actions concept, it's straightforward and the documentation is fantastic, even if it is sometimes easier to search Google for it ;-)
Failing that, CakePHP is a lot better now than it used to be back in the early days, and you can get going with the minimum of fuss, particularly with their scaffolding which will help you set up a basic CRUD-style setup. Their documentation is also pretty awesome and very easy to read :-)
If solutions such as Doctrine, CAKE, CodeIgniter, etc. seem like overkill for what you're trying to do, I'd recommend a one-file PHP script I built that lets you CRUD hierarchical data in MySQL:
http://coding.pressbin.com/109/PHP-One-file-CRUD-front-end-for-hierarchical-MySQL-data/
Why do not you try to code it from scratch as CRUD is a common task of programming.
There are lots of good tutorials:
1>PHP PDO + Bootstrap Twitter: http://www.lizardgrid.com/blog/php-crud-tutorial-part-1/
2>JQuery + PHP: http://www.codeofaninja.com/2013/05/crud-with-php-jquery.html
I am currently testing JqGrid (a Jquery Table Library).
I have tried Grocery CRUD: looks nice, but its Datatables theme (which has column filtering ability) won't work with server-side processing, that's why I dropped it.
You may have a look at Cygnite Framework
It does basic code generation. Controller, model, views, layout, pagination, form component, required field validation, with bootstrap template etc. all these generate with simple command. You may alter the code based on your need.
Here is the tutorial- Generate CRUD application within 2 Min
Worth looking.
I'd say that totally depends on what you need to do.
You do know phpMyAdmin, right? You can import from a lot of formats with that tool.
Or do you want to develop an application with simple CRUD operations? Then a framework like Symfony or Zend Framework would be the right thing to be looking for.
I developed this script which reverse engineers from a MySQL database a set of stored procedures that list all the rows of a table, a single row based on the primary key, updates/inserts based on the primary key and deletes based on the primary key. It assumes that you already have your tables created with the primary keys setup per table and it generates the MySQL stored procedures for you. I have found that this is more efficient than similar types of solutions developed in PHP.
Something like http://www.notorm.com/ might be more appropriate than Symfony. Whilst I like Symfony and have used it to great effect, it is not simple.
Likewise with Codeignitor I would argue that any full stack framework (Laravel, Zend, Wii etc . . ) would not fit the remit of "simple".
A fairly straight forward and effortless crud system i found is https://github.com/usmanato360/crud360 its very easy to setup and there are loads of advanced features. It is unlike traditional crud systems that generate model classes etc.. it is just a single class that takes care of everything dynamically.