HABTM association not being saved? - cakephp

I'm attempting to create a simple 'tags' type of setup, allowing admins to 'tag' an image so it shows up in certain places. I've only started development and wanted to tackle this portion first. I literally just finished running bake, so everything at the moment is standard and I haven't touched any of the generated code.
I have three tables - Tags, Images, and Images_Tags. When I hit /images/add I see the tags I've created listed in a nice multi-select box. I enter the info, select some tags, hit submit. Once saved, I'm redirected to the index and I noticed there are no tags listed for the image I just created. Digging deeper, there are no records in the Images_tags table either.
I'm thinking something is off with my model, or I have a bad database column name somewhere that's borking the default methodology.
Any ideas where I could look? I'm a newbie to cakePHP, go easy on me :)

Here are a couple of things to look at.
From the sounds of things, the images are not being saved. This means that if images are not being saved, nothing will appear in the images_tags table. So the images create/save feature needs to be looked at more closely.
To troubleshoot this, since you have not touched the code, use scaffolding:
var $scaffold;
in the top of the controller and try adding the image again. See if that will allow you to add images. Typically, when something like this happens, its because the schema for the table has changed after baking all of the functionality for the table.

Related

Rich text field is not showing the published (EVOQ) version of inner app

First off I would like to say your product is amazing! Has made the job of inheriting an old DNN instance a much more intuitive experience.
Apologies if this is really simple thing I'm missing but I'm at a dead end after scouring the docs and internet.
I'm using Evoq content and up until the start of the week the publishing workflow had been working fine rich text WISIWIG fields but it seems something has changed. Now when publishing changes any apps that are embedded in rich content fields display the demo item when not logged in.
I've recreated the issue on a smaller scale to illustrate the problem:
When logged in it looks as expected - on the left is a button that's placed directly onto the page, on the right is a button inside a rich text field:
logged in
And when logged out:
logged out
As you can see the button that is embedded as a rich text field is displaying the demo item.
I've gone through all of the content items and ensured that they are set to publish and not draft or hide and ensured the page is set to published in DNN.
Aldo I've double checked how the fields are setup but as this was working previously, I'm doubtful that this is the issue but for clarity here is how the fields look in the model:
Rich text field model
And it's rendered to the page using:
#{
var renderSvc = GetService<IRenderService>();
}
#renderSvc.All(Content, field: "BodyContentBlocks", merge: Content.Body)
I've been scouring the docs and internet for hints of what might be going on but the closest I could find was this thread on github but it doesn't seem to be quite the same issue.
Any help would be massively apricated as this issue has cropped up just before moving to our production server (as they always do!) after working as expected for a couple of months. Let me know if you need any more info from me and thanks for your time.
Evoq has a page-workflow feature which is technically undocumented. 2sxc got a sponsor a few years ago who paid for the implementation but there are limitations to it. Some background:
Some data in 2sxc can be clearly assigned to a module or page - such as content added directly
Other data cannot be assigned to a page - such as a blog post
Because of this, the logic is to first determine if something is partOfPage and if yes - and workflow is active - then it will be set to be a draft. This way the end users don't see it.
Upon page-publish, everything that is partOfPage will be published, so the draft will become the live data.
I assume the detection of this was never implemented for inner content - I think inner-content was actually developed later. Because of this, I assume the toolbars for the inner-content-item tell the UI it's part of the page (resulting in draft), but the publish cycle doesn't know about this, since it's internally a sub-entity (which is just like a tag on a blog - not part of a page).
This is difficult to fix. A proper fix would require 2sxc to be modified to make sure that inner-content is never seen as part-of-page, OR that it's taken into account when publishing. Both of these options would probably take ca. 3 days of dev on 2sxc side and would only happen if we have a sponsor.
A workaround is to disable the Evoq-integration so the page publishing wouldn't happen. I believe there is a feature for this - and AFAIK you don't even have to become a Patron (which I highly recommend to support our thousands of hours of work):
Or you could manually try to publish it, but that will be difficult. Note that most of us will be on x-mas vacation so we won't be answering questions till mid Jan.
Summary of options
Avoid inner content for now
Disable Evoq Page Workflow in 2sxc
Manually publish the items (very difficult, needs super-user permissions because it's an unusual thing to publish)
Get some budget ca. 3 days to sponsor the feature https://2sxc.org/contact but wait till end of January
A mix of short-term solution + sponsoring
Sorry for the delay on this, I've been waiting for a decision. I'm going to close the question as we have been able to work around the issue for now with the help of your last comment. Avoiding inner content is working well enough for our use case. Thanks for your time and help and for making an amazing product!

Approach for building a Gallery of images (ParentalKey vs StreamField)

I'm trying to decide between using ParentalKey or StreamField, in this case, with the purpose of adding an image gallery to a page.
We don't need any other information than the image itself (given that the image will be anyway a wagtailimages.Image model's instance, so the alt text is already handled there).
Any thoughts on what is better to make it easier for the editor to work even if maintaining around 50 images per page?
And about good practices and code maintainability?
Would you prefer a third party package for the image gallery? (even if that blocks you from upgrading to wagtail 4?)
Would your opinion change if instead of a single image, we needed some more fields?
Many thanks!
For an image gallery, the first recommendation would be to use the Collections feature. You can get pretty far with the nested collection system and even add extra meta data if needed by adding a model that relates to the collection.
If that is not suitable, ParentalKey/InlinePanel would be my next pick. For simple relationships you get all the benefits of StreamField such as re-ordering, add/remove items but with solid database integrity and usage stats working out of the box.
Only go to StreamField if you need to have optional data set against each image. For example if you have an image list but images could be an Image with a RichText OR just an image.
Unfortunately, managing large sets of images is not great (outside of collections) so you may find you need to build a seperate UI for this. If that ends up being the case you will find migration of data already in model relations being easier to do or maybe not even needed with something like ModelAdmin.
Hope it goes well, be sure to write a blog post about what you end up doing.
I would use the ParentalKey with InlinePanel for that. It shows you all the images as a list in a more compact way than the StreamField. One can reorder this list.
A StreamField is more expandable in the future. You could add new blocks, like videos or quotes or whatever at any point. If you define each block as StructBlock, you will be able to add whatever you want in the future to these blocks without loosing existing data (also true for the ParentalKey model).
I would not use Collections for image slideshows as you won’t be able to sort the imagas in a collection via the CMS, right? Collections are meant to keep order in the backend, I think.

CakePHP show and hide form fields dynamically

I have a CakePHP website used by multiple clients. Each client shall be able to see slightly different input fields in forms. This is due to client preferences.
A simplified example:
Clients should be able to look up books from a big list. While some clients prefer to look up by author, others might want to look up by publish date or title. But each client should only see one input field in his search page. I don't want to bother the client with too many choices.
While creating different themes and switching them for each client is an option, it quickly becomes a lot of work if we are talking about many views and many input fields. Same for placing lots of if/else in the view files.
The Controller logic could be shared for all clients, as an empty or not existing input field will be ignored by my controller when looking up books.
Optimal I have some kind of dynamic configuration which states for each client which input field to show or hide on which page.
Let me know any suggestions on this or what is a good CakePHP way to achieve this.
If I get this right just use an element per client:
echo $this->element('client_forms/' . $clientIdentifier);

Storing Images in SQL Server database

I'm trying to create a sample ASP.NET MVC application with a ViewModel and onion architecture - very simple online shop.
So as you suppose this shop has products, and each product should have one very small image and when user clicks on that product, he is redirected to a details page, and of course he should see a bigger image of the product.
AT first I thought, it's a simple application, I would (internet) links to the pictures in the database. But then I thought, ok what about when this image is erased from internet, my product will no longer have an image.
So I should store those pictures in the database somehow. I have heard about something called FileStream that is the right way but I found no material to understand what is that.
I hope someone would help me.
There are several options. You could save the picture in the database using a varbinary.
Read here how to read it using MVC.
When you opt for a solution where you split database and file storage, which is perfectly possible, you should consider that it could mean extra maintenance for cross-checking deleted records, etc.
If you choose the last option, the information in the article will mostly suite your needs too.

cakephp finding multiple images and displaying them (possibly outside webroot?)

I am currently trying to build a cakephp app that will list items from a database, and there is a field in the database named picture. This picture field contains a string which is the primary picture, so for example ABCD, and then in the images folder this is ABCD.jpg
However there is usually various extra pictures for this particular item, which may be named ABCD1 or ABCD_2 or some other such variating suffix. I had previously written some script in php which used a glob function and counted the files and outputted them.
I am seriously struggling to do this in cakephp, at the moment there is several thousand images stored in the webroot of the server in /images and I understand that cake will be looking in the webroot of the app like /app/webroot, so is it possible to view their original location? or must they be moved...
I have read a little about the file and folder classes but I am struggling to comprehend them, not sure if my brains failed me here or if this is actually a difficult concept..
my question is how would I find any files that begin with this prefix in the picture field after selecting by the id of the item, to then display all those that match for that particular item?
thanks for your help!
Not a real answer to your question but you should start making a database relationship with your pics.
Check out hasMany to make a relationship between your Article (or whatever it is) and the Picture models. Now you will not have to look for each filename, as you'll have it in your database.

Resources