cakePHP 2.6 FormHelper change template - php

everyone.
I have to change the template of the FormHelper. Not for just 1 or 2 view, for ALL views. And i would like to do this without to have to write hundred of line in every view.
Is it possible to change the FormHelper default template ?
Where the default template is located ?
CakePHP documentation don't say anythings in order to change template of Whole Site, for FormHelper or Paginator, that's a real problem.
I'm not with CakePHP 3 but only CakePHP 2.6

If I understand correctly, you want to modify or use their own "bake" template, in order to avoid repetition of writing html and php code.
Here is what documentation say:
http://book.cakephp.org/2.0/en/console-and-shells/code-generation-with-bake.html#modify-default-html-produced-by-baked-templates
If you want to modify cake helper, copy from
\cakephp\lib\Cake\View\Helper
in the \cakephp\app\View\Helper
and then make modification.
Here is documentations for creating own helpers
http://book.cakephp.org/2.0/en/views/helpers.html#creating-helpers

Well...the file you are looking for is located in
/lib/Cake/View/Helper/FormHelper.php
You should search for example for:
function input(
or
function create(
that is the "template" you are looking for.
I think the easiest way to change the output is to update your $options array. There you can add classes or labels or whatever.

Related

Can I include php file in .tpl?

Can I include a php file to tpl?
All I need is data from the database. I tried with required('path/file.php') but without success.
I already have controller for that. I need to include controller/file, class/php extension anything just need in tpl. I use OpenCart version 2.3.
if you need data from the database, in MVC a model should be used, and then let the controller add it's data to the $data array, which the is available to the template.
this shows how OpenCart actually works (source):
now tell me how your attempt to change a template (view) fits into there (notice the vertical lines).
just load the model into the controller and add results to $data, then it's available in the template.
You should not directly mix templates with custom PHP code, even if in some template engines it's possible.
You should rather look into means of providing your PHP logic through functions, filters or macros. This way you make your PHP code available in templates.
If OpenCart uses twig, you could look into how to do such in the documentation about extending twig here.

Using theme custom form data as config variable

I'm trying to set up my website so changing one config value reflects in a site-wide change. The most obvious example is changing the site title.
I tried using config('constants.site_title') or something like that but it doesn't look like it can be accessed on the twig without initializing it in the php code section.
I tried using plugin's Settings as outlined in https://octobercms.com/docs/plugin/settings#backend-pages but that also was hard to access from the twig views.
Finally I found that using theme custom form data works (see https://octobercms.com/docs/themes/development#customization). Is this the right way to do it? I feel like this use case must have been encountered before and there must be a best practice for it.
Is this the right way to do it?
I think its a reasonable choice - supports most of field types including repeater, has its own "Configure customization options for the active theme" permission, and is easily accessible everywhere in Twig with {{ this.theme.<field_name> }}

Joomla output override from plugin

Is there a way to override a component's output from a plugin? I'm aware of the concept of template overrides, but I just don't want to put the code into the template because
it simply feels wrong to put the code there because it is not a feature tied to the template. In my opinion the template should only contain overrides to fit core output into the template
I may want to add parameters to change behaviour (i.e. there is business logic involved and I want to keep it all together - in a plugin)
I may reuse it at another webpage and obviously don't want to copy & paste the code to all the templates I use
Or are my considerations wrong and the answer is: Just keep it simple and put it into the template?
I found a tutorial about Adding custom fields to core components using a plugin in the joomla documentation where the costom fields are addet to the view with a template override - which seems odd because the rest is done in a plugin - so i assume there is no way to to an output override from a plugin?

PHP layout (template) page

I am new to PHP, lately I was working mostly with .NET MVC 4.
In MVC you can make a layout very easily, end every view knows to use it without telling each view seperatly.
I am trying to figure out what is the best equivalent in PHP.
I have not found a satisfactory answer yet. The best on was to create a 'header.php',
and for each view add a require/include.
I think this breaks DRY, because on each view i need to specify the header. What if I decide to change the file??
Does anyone has a better suggestion?
I am using codeigniter also.
Thank you!!
As you are using CodeIgniter, there is absolutely no single reason to touch require/include commands.
You can load your header views either from the controller or from the main view. If you are worried about file name changes, create a new config file, add it to autoload.php and import your filenames via $this->config->item('config_var_name')

Dynamic menu with symfony layout

I started using symfony a few weeks ago, and there are some things that are not clear for me.
My question is that how could I put a list of categories (for menu) in the main layout of an application? How can I pass a variable for this layout and where to put this variable? I don't want to put it in every module.
Thanks.
Did you read about components, slots and partials? Start here: http://www.symfony-project.org/gentle-introduction/1_4/en/07-Inside-the-View-Layer#chapter_07_code_fragments
And here's the best menu plugin ever: http://www.symfony-project.org/plugins/ioMenuPlugin
You can't pass variables for the layout. Instead you can use partials or components.

Categories