Welcome Guest, Not a member yet? Register   Sign In
Widget plugin (intelligent view partials)
#41

[eluser]sigork[/eluser]
I used this widget to show "Latest Articles/Comments/etc."

But now I'm trying to understand whether it can be used as a Words Limiter.
If I get in Views, for example, Article Text:

Code:
<div>&lt;?=$row->article?&gt;</div>

Can I transfer this $row->article to the Widget?

I saw I could transfer 'int' and $_POST (in previous examples), but how about text variables in Views? To process them in widgets?

Thanks.
#42

[eluser]umefarooq[/eluser]
yes you can pass to widget like this

Code:
&lt;? Widget::run('your_widget',$row->article);?&gt;

class you_widget extends widget{
  function run($article){
   do what you want with article
}
}
#43

[eluser]Unknown[/eluser]
In my project i use own Template library.

widget class send data in browser, here some improvements. Method output returns data as a string:

in widget_pi.php
Code:
function output($view, $data = array())
{
    ob_start();
    $this->render($view, $data);
    $return = ob_get_contents();
    ob_end_clean();
    return $return;
}


in widgets
Code:
&lt;?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Topmenu extends Widget
{
    function run()
    {
        $query = $this->db->select('id, name, uri')->from('menu')->where('show_top', TRUE)->get();


        if ($query->num_rows() > 0)
        {
            $data['links'] = $query->result();

            $return = $this->output('topmenu', $data);
            return $return;
        }
    }
}
#44

[eluser]sigork[/eluser]
Can Widget take config data from Module?

Can I use $this->config->item('Parameter', 'my_module') if there is modules/config/my_module.php with Parameter ?

Thanks. (I tried, no result, maybe my mistake)


P.S. I want to use a widget and a module togeher; widget should check whether there is a config parameter (or to take it from DB table created by the module -- 2 alternatives for users: to use FTP or DB/http)
#45

[eluser]dinhtrung[/eluser]
I tried to write a comment widget, which will display a comment form.
For guest (not logged in), I use 2 flashdata (captcha_word and captcha_time) to check for Captcha validation. But it just won't work.
I read the plugin code and see that it create a new object of current CI. Is it the reason why validation using current object and new created object failed???
I tried to read the logs file, but it just generate too many lines and I gave up.
The widget is something like this:
Code:
/* File : widgets/comment_form.php */
class Comment_form extends widget
{
   function run()
   {
       $captcha_config = $this->config->item('captcha', 'form');
       $this->load->plugin('captcha');
       $captcha = create_captcha($captcha_config);
       $this->session->set_flashdata('captcha_word', $captcha['word']);
       $this->session->set_flashdata('captcha_time', $captcha['time']);
       $this->render('form_captcha', $captcha);
   }      
}
/* File : widgets/views/form_captcha.php */
&lt;?php
    echo form_open('comments_handle/create');
    echo form_label('Name');
    echo form_input('name');
    echo form_label('Email');
    echo form_input('email');
    echo form_textarea('body');
    echo $image;
    echo form_input('captcha');
    echo form_submit('OK');
    echo form_close();
?&gt;
/* File : controllers/comments_handle.php */
...
function _valid_captcha($code = FALSE)
    {
        if ($code == FALSE) $code = $this->input->post('captcha', TRUE);
        $config = $this->config->item('captcha', 'form');
        $time = $this->session->userdata('captcha_time');
        $word = $this->session->userdata('captcha_word');
        list($usec, $sec) = explode(" ", microtime());
        $now = ((float)$usec + (float)$sec);
        if ($now - $time > $config['expiration']) {
            log_message("debug", "Validation for Captcha expired. Now is $now and Time is $time.");
            return FALSE;
        }
        if ($code != $word) {
            log_message("debug", "Validation for Captcha differs.");
            return FALSE;
        }
        return TRUE;
    }
Please give me some advice. Thanks.
#46

[eluser]Buso[/eluser]
does this work in codeigniter 2 ?
#47

[eluser]luke holder[/eluser]
I would also like to know if this would work in codeigniter2. I thought they will be getting rid of plugins.
#48

[eluser]wiredesignz[/eluser]
Convert to a helper for CI 2.0
#49

[eluser]luke holder[/eluser]
thanks wired... are you asking or telling? hehe.
#50

[eluser]Abu eldahab[/eluser]
Thanks wiredesignz for making our life easer, I used it with "Modular Extensions - HMVC" As Library and every thing worked very fine

Thanks Again
Best Regards




Theme © iAndrew 2016 - Forum software by © MyBB