3

Now before you burn me at the stake hear me out!

I want some keywords of a product description field to link to other products (kinda like mediawiki links), however at some point I need to make these associations and link the keywords up, so I'll need to do a search on each curly-braced word I find in the description and produce a formatted version of the description to cut down on processing these keyword links every time the description is displayed.

For ease/consistency I am creating all product links with a custom helper, and all I need to do is pass the product row in and the helper products a link for me with any options I specify. The only this is, is that I need to now do this in beforeSave() so I can populate description_formatted.

At the minute, beforeSave() checks for the original description row, then calls a private method in the model which matches each keyword, queries the db for a matching row... that is as far as I've got.

2 Answers 2

2

Just like any other MVC, Cake makes big restrictions how to couple your classes. This is needed to keep script kiddies to shoot themselves in the foot. However, there is a niche workaround for cake if you really need to get along: http://book.cakephp.org/view/933/The-App-Class

Sign up to request clarification or add additional context in comments.

Comments

1

How I would do this? With the helper I would replace all curly braces words into links and when the user hovers the linked word I would call an Ajax which will get the word description or the link or whatever you need to do. This way you request the description only when it's needed.

If you still insist to use the helper - it's just a class in PHP, so you can include it in your Model, create an object of the class and use it's functions.

The third option is to create your own class and use it both in Model and the Helper.

1 Comment

All I'm doing is linking the curly braced words, but I need to do a query on the name for each word, something I only want to do once when the description is saved, but getting the link requires my custom helper.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.