Welcome Guest, Not a member yet? Register   Sign In
HMVC: How to use module for dynamic widgets
#1

[eluser]Mark K[/eluser]
Is this possible? Because I think one cannot just transfer a module from a project to another project.
#2

[eluser]InsiteFX[/eluser]
You would need a database table to keep track of all the installed modules and then execute it if it is installed.
#3

[eluser]ivantcholakov[/eluser]
I can transfer a module from one project to another, but I am the author of both of the projects and I follow my own conventions. This is possible. Especially when I use Bootstrap for styling - I don't heed to rework my html while transferring a module.

You asked for more than that - some kind of plug-in system. But it would require some standardization, if you want many developers to use it. I think, a CMF project (Content Management Framework) should address such feature implementation. Some CodeIgniter based CMSs has it, but in their own way.
#4

[eluser]Mark K[/eluser]
Thanks for the reply guys. I'm just thinking if I can create widgets in HMVC. For example, if I will create a login widget, how am I supposed to put a redirect on that login widget if it is located on different main page?
#5

[eluser]ivantcholakov[/eluser]
@markandrewkato

A widget has no its own web-address accessible by the browser, It just creates a HTML-fragment. When you say "how am I supposed to put a redirect on that login widget..." it is unclear what you want to do.

I need to say that modular approach and on the other hand HMVC (the "widgets") are different concepts. I have the habit to create "login" module, it is a normal page, not a widget.
#6

[eluser]Mark K[/eluser]
I am very sorry but I'm still confused. Let's have an example. Let's say I want to create a login widget (which is a module).

View:

Code:
<?php

echo form_open(base_url() . 'login/widget');

echo form_label('Email: ', 'txt_email');

$data = array(
    'name'          =>  'txt_email',
    'id'            =>  'txt_email',
    'type'          =>  'text',
    'placeholder'   =>  'Enter email address',
    'autocomplete'  =>  'off',
    'maxlength'     =>  '24'
);

echo form_input($data);

echo '<br>';

echo form_label('Password: ', 'txt_password');

$data = array(
    'name'          =>  'txt_password',
    'id'            =>  'txt_password',
    'type'          =>  'password',
    'placeholder'   =>  'Enter password',
    'autocomplete'  =>  'off',
    'maxlength'     =>  '16'
);

echo form_input($data);

echo '<br>';

echo form_submit('btn_login', 'Log In');
echo '&nbsp;';
echo form_button('btn_forgot', 'Forgot');

echo form_close();

Controller:

Code:
function widget() {
        
        $redirect_location = "name of url to redirect";
        
        if($this->input->post('btn_login')){
            
            $username = $this->input->post('txt_email');
            $password = $this->input->post('txt_password');
            
            if(Modules::run('user/validate_login', $username, $password)) {
                redirect(base_url() . $redirect_location);
            } else {
                redirect(base_url());
            }
        }

        $this->load->view('widget');
    }

If I want to have a login on two (2) different pages, I simply call the login module which is Module::run('login/widget'). For this example, how can I handle the redirects if this will be on two different pages? The solution that I think of is to pass variables. But is it a good practice?
#7

[eluser]InsiteFX[/eluser]
pass it in parameters so that it knows what page to redirect to.

[code]
function widget($data)
{
redirect(base_url($data));
}

// Module::Run
Module::run(‘login/widget’, $data)
[code]
#8

[eluser]ivantcholakov[/eluser]
So far so good, the idea is nice.

For better user experience when login fails, the form with a feedback message should be shown instead of silent redirection to the home page.
#9

[eluser]Mark K[/eluser]
Thanks guys. Passing variables is my only solution to redirects. But I feel I'm doing something wrong. I don't know what. Also, that's my other problem. I think loading the view instead of redirecting when login fails is more proper. Like the old fashioned MVC coding below:

Code:
function login() {
    
    $data['error'] = "";
    
    if($this->input->post('submit')){
        /** verify login **/
        redirect('url here');
    } else {
        $data['error'] = "Invalid login";
    }
    
    $this->load->view('login_view', $data); /*** load view instead of redirecting in else ***/
}




Theme © iAndrew 2016 - Forum software by © MyBB