ViewScript decorator unable to set - php

I am following the section about "Full Customization Using the ViewScript Decorator" from this page -> http://devzone.zend.com/article/3450
In the init method of my form class I have added this
$this->setDecorators(
array(
array(
'ViewScript',
array(
'script' => 'display.phtml'
)
)
)
);
Now in the place where my form appeared I have this:
An error occurred
Application error
What am I doing wrong here? I really need to customize the appearance of the form and I just want to change the form and not the appearance of the whole page.
I have tried this:
$this->setElementDecorators(array(array('ViewScript', array('viewScript'=>'display.phtml'))))
Which works but affects the display of the whole page (I am using zend layout). I just need the render of the form to be passed to the display.phtml page.
Note: Is there any place in particular I have to place the display.phtml? I placed it in the view\scripts folder.

I think it is as simple as this.
The ViewScript cannot be used in the init() method for your form for one simple reason. If you look at the example (and probably your display.phtml) there are echo statements like this one $this->form->firstname;. At this point in init() the form elements are not loaded yet!
The author therefore correctly shows this code
$form->setDecorators(array(
array('ViewScript', array('script' => 'demogForm.phtml'))
));
Note that he uses $form as the object. Either in controller or view script you load your form as an object and then add the ViewScript. So in one of your controllers you would do something like this
$form = new My_Form();
$scriptPath = '/path/to/script/display.pthml'
// or without a path if you have a script folder loaded
$form->setDecorators(array(
array('ViewScript', array('script' => $scriptPath))
));
This should do the trick.
Update Looking at the naming of your pthml I assume (and hope) this is a special template for your form and not your whole layout file. If you use your whole layout file then of course if will render the whole page!

When working with view scripts, I find it's best to make any such changes at the view level.
Ignore the "ViewScript" decorator details in your form and set them from the view, eg
<?php echo $this->form->setDecorators(array(
'PrepareElements',
array('ViewScript', array('viewScript' => '_forms/display.phtml'))
)) ?>
The location of the display.phtml file is relative to the module's view scripts folder. If this is just the default module (under the application folder), the script in my example will be located at application/views/scripts/_forms/display.phtml

If you want to remove HTML tags like <dt> or <dd> (labels and viewscript) you can use methods removeDecorator('HtmlTag') or removeDecorator('Label')

Related

How to change Sign up page design in Moodle

I am new to moodle and i am using 2.9. I have a separate design for Signup page (HTML5 & CSS). How to integrate this page ?
I know the process of changing the default Login page like this
In config.php of my theme
'login' => array(
'file' => 'login.php',
'regions' => array(),
'options' => array('langmenu'=>true),
),
Where my Custom login page is login.php which is placed in my layout folder. So in this way i can takeover Login page design with my new design.
But i don't see any signup array in config page for Registration. So anyone can tell me how to do this change ?
Edit - I have checked this file moodle2\login\index_form.html I can see the signup design. But my issue is that file index_form.html has Moodle core CSS if i add my CSS there it will conflict also i dont know how to load the CSS from my theme folder to index_form.html.
Can anyone guide me ?
I already checked Moodle.org forum but not able to find the process.
Thanks In Advance
Lorry
Further to what #davosmith mentioned, you can actually use the existing auth/email plugin as a base for your plugin, So:
Copy auth/email and rename it to whatever you want, for example auth/foo. And rename all other instances of "email" to "foo".
Copy the login/signup_form.php to your plugin directory
in your auth/foo/auth.php file, add a function:
function signup_form() {
global $CFG;
require_once($CFG->dirroot.'/auth/foo/signup_form.php');
return new login_signup_form(null, null, 'post', '',
array('autocomplete'=>'on'));
}
Modify the auth/foo/signup_form.php to whatever you want
Hiii,
I'm one of the Moodler who working with Moodle.
to edit the signup page go at the following location and open the signup.php file.
./moodle/login/signup.php
in that file you can see at bottom of the page three lines.
...
echo $OUTPUT->header();
$mform_signup->display();
echo $OUTPUT->footer();
in which $mform signup->display(); create a form yu can comment and write HTML for your sign up form.
But make sure about the Action URL and the validations.
$mform is the object that create form and its class file is signup_form.php.
Hope it helpful for you ... Good Luck ['}
If you are wanting to avoid making changes to the core code in Moodle (which should almost always be what you want), then you can create a new signup form from scratch by first creating a new authentication plugin (in auth/NAMEOFPLUGIN).
When you create the authentication plugin, you should make sure that the 'can_signup' function returns true, that the 'user_signup' function does whatever processing is needed to create the new user account and that the 'signup_form' function returns a custom Moodle form that contains the fields you want.
It is possible to further customise this form by outputting custom HTML elements (using $mform->addElement('html', 'The HTML to output'); ). I would not advise completely abandoning the Moodle form (i.e. to replace it with hand-coded custom elements), as that will not be compatible with the signup code in login/signup.php (as well as losing the validation rules that are supported by the forms library).

When I use CListView widget in YII the fontsize of my whole website changes. (I use flowtype for fontscaling)

When I use my CListView Widget in a page the fontsize of my whole website changes. I use flowtype to scale my fonts and keep everything responsive. Only when I use this widget everything changes, nog only the data of the widget itself.
I tried to turn the css styling of the widget of and tried to control it via an own css file, but this doesn't matter.
<?php $this->widget('zii.widgets.CListView', array(
'dataProvider'=>$dataProvider,
'itemView'=>'_view',
'cssFile'=>false,
)); ?>
The content of the view I'm calling doesn't matter either. Only when I remove the widget and put some text instead it changes back to normal.
Does someone have any idea what's happening here?
Quoted from official documentation for ClistView
cssFile property
public string $cssFile;
the URL of the CSS file used by this list view. Defaults to null,
meaning using the integrated CSS file. If this is set false, you are
responsible to explicitly include the necessary CSS file in your page.
Follow it, when you used CListView, default css .../listview/style.css file would be imported into your page, it could change your current layout if some of css is coincided with each other.
You can override it
$this->widget('zii.widgets.CListView', array(
'cssFile' => 'your-css-file-path.css',
...
)
So, eventually tried to copy the parsed code from the page source into my view. So in pagecode this was exactly the same output as the widget does in the page. Now I didn't had the resizing problem. So the widgets do something more then I can see.
For the solution I wrote an own widget to get my data in which I can control everything that happens. So no problem left anymore. Thanks for your help Telvin!

Within Codeigniter, how do I write a view file to a view file?

I have a thank_you.php file that simply contains the string "Thank you." formatted in a successful / green color.
I'm wanting to display this text on a specific region of the site, but not sure how to go about it. Within my main view file, I added the line:
<?php $this->template->add_region('success'); ?>
next to the "Submit" button.
Within my controller, I have a function that should, once called, display the view file "thank_you.php".
function greeter_thank_you() {
$this->template->write_view('success', 'thank_you.php');
}
I have the standard $alert, $content, $main, etc... regions within my Template file, but how do I echo this view file onto another view file? Is there some other way I need to go about it?
It seems you are using Collin Williams' CI Template library.
As far as I know, you can't define a region inside another one, so it is better to send the value of the internal region (which you called it success) into the main region.
If you are using $this->template->write(); method to write content to the main region:
Get the content of thank_you view file by using $this->load->view('thank_you', '', TRUE); and place it somewhere inside the second parameter of write().
If you are using $this->template->write_view() method:
Use the following:
$data = array(
'foo' => 'bar',
'baz' => 'qux',
'success' => $this->load->view('thank_you', '', TRUE)
);
$this->template->write_view('main', 'main_region_view_file_here', $data/*, TRUE*/);
And add the following inside the view file of the main region:
if (! empty($success)) {
echo $success;
}
I don't have any experience with Collin Williams' Template library, but I think this might do the trick.
By the way, If you had any problem, I'm all ears!
if you want to to load one view file within another view file.
Just type
$this->load->view('FolderPath/FileNameHere');
I Hope it solves your Problem.
Edit:
Or if You are Tying to Load another View after Performing some action on Button.
You can redirect your button to that controller.
and there you can write the above line.
if it is a anchor Button just put <a class="BtnClass" href="ControllerPathHere">Submit</a>
and if you are using some templates Library Please tell more about it.
In the controller, you want to buffer the view output to a variable, and pass the variables to the template. The third parameter in the view method allows you to return the view output as a string.
$viewData = array(
'main' => $this->load->view('thank_you.php', '', true)
);
$this->load->view('template.php', $viewData);
// access the main template data with $main in template.php
See the bottom of this page: http://ellislab.com/codeigniter/user-guide/general/views.html
1-You can pass it like this:
function greeter_thank_you()
{
$data = array();
$thank_page = $this->load->view('thank_you');
$data['thank_you'] = $thank_page;
$this->load->view('main',$data);
}
inside your main page
<html>
<body>
<div id='thank'>
<?=$thank_you?>
</div>
<!--The rest of your codes-->
</body>
</html>

opencart - How to manually display a module inside a template file?

Let's say I want to display the specials module on the homepage in a position different than $content_top, $content_bottom, $column_left or $column_right. How do I do that? If you have some experience with this, could you give me some pointers?
The module will be display in home.tpl but I'm assuming I would need to edit the controller file home.php
To do this, you will need to make edits to two files
Firstly, you will need to edit the controller. In this example, I'm going to add the specials to the home page
So open the controller file catalog/controller/common/home.php. Somewhere before this line $this->response->setOutput($this->render()); add the following
$this->data['special_block'] = $module = $this->getChild('module/special', array(
'limit' => 5,
'image_width' => 80,
'image_height' => 80
));
The array is the settings for the module. Note that the layout, position, status and sort order aren't included, as they're irrelevant here. I've also used special_block as a unique key for the content, to avoid it conflicting with any other items that may need rendering
Then in your template file, you just need to use <?php echo $special_block; ?> wherever you want the module to go

How to embed modules on pages?

I have created my own extension and modules. I can view the modules fine, by going to their URL. However, now I want to embed them on a page, much like a content class. How do I go about doing that?
Thanks!
You have to create template operator or function and use them in template.
It is not possible to "embed" a module in a page except if the module which is called do it at the PHP level.
For instance, it's possible to write this :
$module = eZModule::findModule( 'content' );
$result = $module->run( 'history', array( 1 ) );
But if you want to display anything related to your module, you should declare that your extension contains some templates and override some templates.
Let's say that you would like to make your own register module.
Step 1, you may have to add this in your_extension/settings/design.ini.append.php :
[ExtensionSettings]
DesignExtensions[]=your_extension
So you are now able to add your own user/register.tpl
This template contains a form like this :
<form action={'/user/register'|ezurl}...
So you just need to copy the template but with :
<form action={'/your_module/register'|ezurl}...
Now let's say that your template is supposed to display some informations related to your module. You may have to define some fetch functions so you would be able to write something like this:
{def $nb = fetch('your_module','beta_accounts')}
<h2>Hurry up! There are only {$nb|wash} available accounts for free!</h2>
<form action={'/your_module/register'|ezurl} method="POST">
...
</form>
I hope that it will help...

Categories