Behaviors
initialize()
, just like the Timestamp Behavior.initialize()
, just like the Timestamp Behavior.There are many file upload plugins for CakePHP (See https://github.com/friendsofcake/awesome-cakephp#file-manipulation ) and they have lots of features. But all I want to do is to simply attach documents to my model and ensure they don't clobber one another so I created my own basic functionality that meets my needs without any added overhead.
In our Database and Model tutorial we covered a very simple example to create a slug for use with a record. One problem with this example is that it doesn't create unique slugs, and since our database requires unique slugs, this could become an issue with two users having the same first and last name.
NOTE: I no longer have access to an Oracle database, however, from what I can tell it all works the same with CakePHP 5 as it did with CakePHP 4.
CakePHP 5 does not provide core support for Oracle databases. An Oracle database driver plugin is available from CakeDC here: https://github.com/CakeDC/cakephp-oracle-driver
It's almost as easy as following the directions there, but there are a few "gotchas" with Oracle.
In the previous tutorial, Table Relationships, we set up associated tables and displaying associated data, but there's no point to displaying associated data if you can't add it first.
There are multiple ways to save associated data. We'll start with the easiest way, discretely.
When working with CakePHP it is important to remember "Convention over Configuration." If you start from the bottom, or back end, the database, and work your way forward correctly, CakePHP will do much of legwork for you, saving you tons of redundant and repetitive work.
If you don't, there are almost always ways to make things work the hard way. An example of this is the relationships between tables. If you name your database tables and fields following CakePHP convention, it becomes trivial to set up relationships between them.
In addition to accessing the fields existing in the database, a Model can be used to create virtual fields for consistent formatting of data that you don't want to store redundantly in your database or have to recreate each time you want to use it.
Now that your application is up and running, it is time to build your data store and interface with that data. We have two options here: We can create the database tables using Migrations or directly in the database, either through the database interface, a web interface, or an IDE interface.