I’ve been trying to develop large scale application in wordpress. Been through several plugin development best practices. And finally I’ve been reading the documentation of http://wpmvc.org/
I pretty much understood its automatic (mvc) code generation tools. Its default controller functions index() & show() works pretty well.
But, when I tried to add a custom_action(), thats where I got stuck.
class DemoController extends MvcPublicController {
public function hello(){
print_r($this->params);
die();
}
}
above function hello() is only accessible by below URL:
domain.com/demo/hello/{num}
but can’t be accessed via:
domain.com/demo/hello
Do I need to write any custom route to make this work? Or, am I doing anything wrong?
Finally, I found the solution, and it was pretty easy.
In config/routes.php,
I replaced, this:
MvcRouter::public_connect('{:controller}/{:action}/{:id:[\d]+}');
with this:
MvcRouter::public_connect('{:controller}/{:action}');
[ IMPORTANT ] Don't forget to save permalinks to flush rewrite rules.
Related
I tried overriding the core classes but this one doesnt seem to work. I know I will need to update the application/config/app.php file to point to the new class. But when I do this the HTML redender stops at head tag.
I extended the Request Class from core to application/src, updated the app.php file, but it doest work and gives me a blank page. I will need this to use redirect url.
if your goal is to do something to the request before sending it back you might want to use a middleware instead of overriding the class.
A good example is the Centry portal package which you can find here: https://github.com/a3020/centry
Have a look at centry\Provider\CentryServiceProvider.php function registerMiddleware() to see how to register a middleware.
And then look at the 2 files in centry\Http\Middleware to see how it's used.
If you are using version 8 you will need to autoload your classes in the src folder.
In application/bootstrap/autoload.php
$classLoader = new \Symfony\Component\ClassLoader\Psr4ClassLoader();
$classLoader->addPrefix('Application\\Example', DIR_APPLICATION . '/' . DIRNAME_CLASSES . '/Example');
From here you will need to override the associated service provider. It's not entirely clear which class you are trying to override and which service provider this would require. Below is an example for overriding the \Concrete\Core\Http\HttpServiceProvider with class placed in application/Src/Example/HttpServiceProvider
return [
'providers' => [
'core_http' => 'Application\Example\HttpServiceProvider'
]
]
From the service provider you can extend classes and override the returned classes in a way the suits your use case scenario (It can be tedious if multiple classes have references but it's the only way I'm aware of to properly override core classes). Typically you can just extend existing classes overriding a single method or two and come up with an elegant solution.
When using a custom front-end theme, the preview button for my content stops working. It just redirects to the content overview page.
Am I missing something in my theme that allows me to use the 'preview' function?
You most likely have the ?destination=admin/content in your URL. This is a core bug. The current discussion can be read at:
https://www.drupal.org/node/2325463
Jason Ruyle's answer is correct, I had the same problem and solved it by adding this code to my module:
use Drupal\Core\Entity\EntityInterface;
function my_module_entity_operation_alter(array &$operations, EntityInterface $entity) {
if (isset($operations['edit']['query'])) {
unset($operations['edit']['query']['destination']);
}
return $operations;
}
The code could also be improved to target the right entities, if needed.
Consider the following scenario:
Test class:
class Test{
protected $title;
protected $description;
}
Base Question class:
class BaseQuestion{
protected $Test
protected $question;
}
Text Question class:
class TextQuestion extends BaseQuestion{
}
Checkbox Question class:
class CheckboxQuestion extends BaseQuestion{
protected $options;
}
So I have all this setup, now I need an easy way for people to create new tests with questions.
I first started by using Sonata Admin as a CMS, which was working fine as long as I didn't use polymorphism and just used 1 type of question. Using the inline option you could create questions when you were creating test. However including the inheritance to Sonata Admin with their inline option proved to be unsuccessful.
I then tried to remove all the Sonata Admin stuff and just build a plain form to do this but again, with only 1 type of question this works very well with embedded forms. But as soon as I tried implementing it with the inheritance classes, things proved more difficult.
I tried using the Infinite PolyCollection Bundle but couldn't find anything on how to display the form. I then found the Arse Polycollection bundle (which uses the Infinite bundle) but can't get it to work even though I was following the tutorial step by step.
Currently it's giving me the following error:
FatalErrorException: Error: Call to undefined method Symfony\Component\Form\FormBuilder::getTypes()
I am getting clueless on how to proceed with this, has anyone got the above bundles working before?
Or do you have other suggestions on how to set up a (small) CMS system for this?
Update:
I basically did everything manual now and it's working but I do hope they include a way of doing this with the framework in the future.
I tried using hook_custom_theme to change the theme for the node add page for a specific content type, like this, without success:
function mymodule_custom_theme() {
if (current_path() == 'node/add/mytype')
return 'anothertheme';
}
I know the function is running, and I know the comparison is returning TRUE. Why is it not working?
I think you are not writing the theme name correctly.
But there is a module which could do this work for you: https://drupal.org/project/themekey
Regards.
1) Do you use the correct machine name for the theme?
2) Are you sure that there are not other modules to override this later?
3) Is the page cached? If so this may not work properly.
Same question and discussion here: https://drupal.stackexchange.com/questions/812/how-do-i-change-a-theme-based-on-the-url
Useful modules:Page Theme, Context, ThemeKey.
We've created a custom module for organizing and publishing our newsletter content.
The issue I'm running into now -- and I'm new to theming and Drupal module development, so it could just be a knowledge issue as opposed to a Drupal issue -- is how to get each newsletter themed.
At this point the URL structure of our newsletter will be:
/newsletters/{newsletter-name}/{edition-name}/{issue-date} which means that we can create template files in our theme using filenames like page-newsletters-{newsletter-name}-{edition-name}.tpl.php, which is great. The one issue I'm running into is that all of the content comes through in the $content variable of the theme. I'd like to have it come through as different variables (so that I can, inside the theme, place certain content in certain areas.)
Is there a proper way for doing this?
Edit: To answer some questions: The issue is a node (there are issue, edition and newsletter nodes) and the path is being set using hook_menu with wildcards and a router.
The best answer I could find was to add a check inside of phptemplate_preprocess_page to send the vars back to the module and have them be updated.
Like so:
function phptemplate_preprocess_page(&$vars) {
if (module_exists('test_module')) {
_test_module_injector($vars);
}
}
then in my test_module.module file I created this function:
function _test_module_injector(&$vars) {
$vars[] = call_to_other_functions_to_load_vars();
}
It seemed to work. I wish there was a way to do this without having to touch the theme's template.php file, but otherwise this works well.
If there were better documentation for template preprocess functions, Drupal would be a lot more accessible - as it is, you need to piece together the information from a lot of different explanations. One place to start is here:
http://drupal.org/node/223430
but if you take the time to work through the tutorial below, you'll find you can do most things:
http://11heavens.com/theming-the-contact-form-in-Drupal-6
This is an old post, and the OP's issues seems to have been solved.
However, just for others finding this through Google (or otherwise):
Install the 'Devel' module: http://drupal.org/project/devel
Also the 'Devel Themer' module: http://drupal.org/project/devel_themer
Use Devel Themer to go through the $content variable and find what you need to pull out.
There are a bunch of Devel/Themer docs/tuts out there, but its usage is pretty straightforward. Note, though, that some stuff in there will need to be sanitized before printing in the theme.
The suggestion to show the node as a View and then modifying the view templates sounds pretty crazy, though it'll work.