Modification Yii CRUD generate (Gii) form template - php

I want to change the Gii template follow my own template that I have where I found the code to change
<div class="errorMessage">....</div> become my own template style??
I have changed most of the gii templates style follow mine but i have not found the line to change the "div" error message on : framework\gii\generators\crud\templates\default

The main view file for CRUD generation is in framework\gii\generators\crud\templates\views\index.php. The form is generated using CCodeForm, and the error messages are generated using the $form->error() method.
You can customise these considerably by just passsing parameters to the $form->error() method as described here, or you can override the $form->error() method by creating your own class which extends CCodeForm, but that may have unintended results!
I'd suggest, for ease, that you pass parameters to each of the $form->error() methods that are called in the view file.
To do this, follow these steps;
Create a folder 'gii' in your protected folder
Create a folder within that called 'crud'
Into that folder copy the entire contents of `framework/gii/generators/crud. These files will now override the default files from gii.
Open protected/gii/crud/views/index.php
Find all the error fields. They look like <?php echo $form->error($model,'controller'); ?>
Add an array of html options to the error declaration, so it looks like <?php echo $form->error($model,'controller', array('class' => 'alert alert-error')); ?>
Thats it! This method has the benefit that you haven't modified the core framework files, so if you update yii your changes will not be overwritten. For more information, have a look at this http://www.yiiframework.com/doc/guide/1.1/en/topics.gii

Related

Override JSON view in RequestHandler in CakePHP

I want to rewrite JSON View in the RequestHandler. So there's a file project_root/lib/JsonView.php. What I want to do is to
Import the JsonView.php file in another file in project_root/app/View/CustomJsonView.php. (I think I could use App:import, would it be right ?)
Choose this file as the custom in requestHandler like this:
public $components = array('RequestHandler' => array( 'viewClassMap' => array('json' => '/right/way/to/this/file/CustomJsonView', )));
But how do I write the right way for this file ?
I also saw this one https://book.cakephp.org/2.0/en/core-libraries/components/request-handling.html#RequestHandlerComponent::viewClassMap
but there is no explanation about the right paths to the file. My CakePHP version is 2.4.4 .
You are not supposed to pass full paths, but "short classnames", just like shown in the linked example, where ApiKit.MyJson refers to the MyJsonView view class in the ApiKit plugin, which could be located in app/Plugin/ApiKit/View/MyJsonView.php.
If you follow the conventions and place your CustomJsonView class in app/View/CustomJsonView.php as shown in the docs, you then just pass CustomJson as the short classname in the request handlers viewClassMap option.
Whether you use App::import() or just require to include the /lib/JsonView.php file, is up to you, both works. In any way you must make sure that whatever you are importing there doesn't clash with existing class names (JsonView is a kinda reserved name as it already exists in the core), and that it is either following the CakePHP view class naming conventions, or you must extend it.
See also
Cookbook > Views > Creating your own view classes
Cookbook > Core Libraries > General Purpose > App Class> Loading Vendor Files

Joomla: Is it possible to display a view of a component without iframe and plugin?

Is it possible to display a view of a component without iframe and plugin?
(That is to say, if possible with a few lines of PHP and maybe SQL queries?)
EDIT:
To be more clear: I'd like to do it directly in the PHP-Template!
(Would be fine to do it in an article as well, as I have written a
PHP-function showArticle(mixed $ident))
(I'm using Joomla 3.5)
I'd like to do something like
<jdoc:include type="component" view="example" name="position-x" />
or
<?php
show_component('component-name', 'view-name');
?>
you can use this component http://extensions.joomla.org/extension/components-anywhere
Install the plugin and enable it.
Then you can call the component this way {component url/of/the/component}
{component index.php?component=com_example&form=1}
Try to use non-sef urls in the url but sef url will still work.
There is another way to achieve this by calling the model into your controller file this way
JModelLegacy::addIncludePath(JPATH_SITE . '/components/com_example/models', 'ExampleModel');
What this does is it searches the model class starting with ExampleModel in the folder specified. here you can eneter just a path string or array of the directories as the first parameter. Next you have to call the method inside the views file this way
$exmodel = JModelLegacy::getInstance('Something', 'ExampleModel', array('ignore_request' => true));
So here you create an instance of the class object which can be used to get the items from the model this way
$items = $exmodel->getitem();
$this->assignRef('items', $items);
next you can copy the default.php file in the tmpl folder of that component and place it anywhere you like inside your layout file. Basically instead of copying the entire component you are calling the model and getting the data which you can use in your layouts.

Style admin page in Yii

Im here again with a question about yii framework.
I've got a page under views/myviewname/admin.php.
I've got a page under views/myotherviewname/admin.php.
Now i want to give those pages another style. But how do i do that?
I've created a page under themes/classis/views/myviewname/admin.php and in that file i got this:
<?php /* #var $this Controller */ ?>
<?php echo $content; ?>
But i get an error. Because $content is not defined.
How do i style those pages? Would be nice if i can style all admin pages at once.
First of all, this is undeniable that $content variable will be known as undefined, since it can only be used in Layouts, not Views.
As you probably know, if you already have set a theme for your application(in main config file by 'theme'=>'myTheme'), Yii looks for that into themes/myTheme and all views will be rendered in themes/myTheme/views/x/y.php instead of views/x/y.php. Also, your layouts will be overridden by layouts located into themes/myTheme/layouts.
Now, lets assume that we want to create 2 themes:
DarkTheme
LightTheme
We should create structures like below:
+themes
+darkTheme
+views
+layouts
+main.php
+myLayout1.php
+myLayout2.php
+myController
+myView1.php
+lightTheme
+views
+layouts
+main.php
+myLayout1.php
+myLayout2.php
+myController
+myView1.php
We have a main.php which holds our base theme structure(skeleton), and 2 layouts named myLayout1.php and myLayout2.php respectively. Also we already defined a default layout into our base controller(Usually Controller.php) like below:
public $layout='//layouts/myLayout1';
Now, we have a main layout which shows everything inside myLayout1 by default. We can change layout in out action like below:
$this->layout="myLayout2";
Also we can change application theme like below:
Yii::app()->theme="lightTheme";
Note: Theme name is case-sensitive. If you attempt to activate a theme that does not exist, Yii::app()->theme will return null.
Above codes can be written into beforeAction() method or every action. Please note that, if you render myView1($this->render('myView1')) and if the theme is set to darkTheme, Yii will render themes/darkTheme/views/myController/myView1.php instead of views/myConteoller/myView1.php.
To be more clear, $content will be used in layouts. Also, this is remarkable that, $content will be replaced by everything inside a view. So if you want to modify the whole page's schema, you must modify main.php layout. In front, if you want to modify the style of a view's content, you need to modify your layout.

How To Include PHP Files In Twig Files In Symfony2

I am trying to insert a latest tweets "widget" on to a Symfony2 project. I have found an ideal script written in PHP that will do the job perfectly.
However, I don't know where the best place to put 3rd party PHP files in a Symfony2 project. I have placed them in the same folder as all my twig files reside, changed the name to read tweets.php.twig, and even located them in the web folder. When I try to include the file in the twig file that needs the Twitter feed it comes up with an error saying that it can't find the file.
Do I have the right idea, or do I have to convert the PHP in to a twig file or write the PHP script in to a controller?
I believe the recommended way would be to create a Symfony2 bundle that encapsulates all the logic for the tweet widget. You would then call your bundle controller and pass the response to your twig template.
If that is too complicated or you want something more quick and dirty - you can create a controller like TweetWidgetController.php and put the code into there as an action like widgetAction. Just make sure you return the tweet widget output in a Symfony response object.
Then from your main controller - you can do something like
$widget = $this->forward('YourBundle:TweetWidget:widget', array('twitterid' => 'yourtwitterid'));
return $this->render('YourBundle:yourtemplate.html.twig',array('widget' => $widget->getContent()));
Now in your twig template you can put it wherever you'd like by referencing it as:
{{ widget }}

Method/function overrides in Codeigniter

I want to override the validation_errors() method of the form helper in CodeIgniter for one controller only, so that it will display a single error message (as a sentence in plain english) instead of the detailed line item summary. I've tried defining a validation_errors() function in my controller, which is what I usually do with Silverstripe's Sapphire framework, but this won't with CI.
What's the best way to override methods for a case by case basis?
You can create a MY_Form_helper.php in your application/helpers/ folder and create that function in there and then when you load the form helper, it should also load your function.
For more information read the '"Extending" Helpers' section on: http://codeigniter.com/user_guide/general/helpers.html

Categories