Yes add parameters. Why don’t you read the widget code in this thread and figure it out for yourself? The very first post has an example passing parameters to a widget.
This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.
The active forums are here.
March 24, 2009 12:29am
Subscribe [34]#61 / Nov 14, 2010 11:05pm
Yes add parameters. Why don’t you read the widget code in this thread and figure it out for yourself? The very first post has an example passing parameters to a widget.
#62 / Nov 14, 2010 11:16pm
I did read it bud. Your examples are short and to the point and often don’t have a lot of explanation behind them. Maybe that should be enough from your point of view but to us beginners it can take a good bit more explaining to fully grasp.
#63 / Nov 14, 2010 11:34pm
So which part of this example shown in the first post of this thread is unclear to you?
<?php widget::run('user_login', (bool) $this->user->is_guest); ?>#64 / Nov 15, 2010 11:23am
Yes that’s perfectly clear that you are passing a param in that line of code. Obviously I wasn’t sure that passing the data in this way is exactly what you meant. All I’m saying is have a little patience..
#65 / Dec 20, 2010 12:22pm
This is pretty cool so I’m going to check it out. Do you know if this works with the Form Generation Library?
#66 / Feb 15, 2011 3:23pm
this works with reactor ? if so any changes needed ?
#67 / Feb 21, 2011 4:27pm
@Quasi
I copy the PHP5 version and put it in helpers folder, autoload it, and works fine.
The only change i do is clareting the functions static, however, without that, the class works fine.
#68 / Feb 22, 2011 3:29am
@ClaudioX ty i will try
#69 / Jul 25, 2011 6:41am
hello,
if i use <?php widget::run(‘somw_widget’); ?>.
it’s echo immediately.
i want to keep it in string, not echo.
how to make it just return value?
thank you. 😊
( i am using ci2+modular extensions+php5 )
#70 / Jul 26, 2011 1:00pm
then echo output in widget run function .
function run(){
echo $output;
}#71 / Jul 26, 2011 1:13pm
@umefarooq
thanks but not that way..
i want it just return value from $this->render()
NOT echo without echo. (please try to call widget from topic example without echo and you will know.)
++++++
from this page http://ellislab.com/forums/viewthread/109584/P20/
Updated Widget plugin for use with Modular Extensions PHP5
my widget
class test extends widget {
public $title = "Test";
public $description = "For test";
function run() {
$this->render("test");
}
}test.php
views/test.php
call widget by
<?php widget::run(‘test’); ?>it will echo, print widget. but i want to keep it in variable, $string
... i want this
<?php
$widget = widget::run('test');
// do something with widget
$widget = str_replace(...);
?>i cannot make it.
#72 / Oct 04, 2011 3:35am
wiredesignz thanks for code. One question - you asked to move file to helper so will it be fine in helper or in library?
#73 / Oct 04, 2011 4:56am
Helper is better than library, The widget class will be loaded but not instantiated until you call widget::run().
#74 / Nov 29, 2011 2:37am
Updated Widget plugin for use with Modular Extensions PHP5
<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); /** * Widget Plugin * * Install this file as application/plugins/widget_pi.php * * @version: 0.21 * $copyright Copyright (c) Wiredesignz 2009-09-07 * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ class Widget { public $module_path; function run($file) { $args = func_get_args(); $module = ''; /* is module in filename? */ if (($pos = strrpos($file, '/')) !== FALSE) { $module = substr($file, 0, $pos); $file = substr($file, $pos + 1); } list($path, $file) = Modules::find($file, $module, 'widgets/'); if ($path === FALSE) { $path = APPPATH.'widgets/'; } Modules::load_file($file, $path); $file = ucfirst($file); $widget = new $file〈); $widget->module_path = $path; return call_user_func_array(array($widget, 'run'), array_slice($args, 1)); } function render($view, $data = array(〉) { extract($data); include $this->module_path.'views/'.$view.EXT; } function load($object) { $this->$object = load_class(ucfirst($object)); } function __get($var) { global $CI; return $CI->$var; } }
as far i know current CI 2.1 don’t have plugin loader,
can i wrote this code into library instead ? but i notice the HMVC MX loader have plug in function.
i confuse, so should i follow the old CI 1.7 method application/plugins ??
or i need to rewrite it as Library put in application/libraries ??
i’m currently on CI 2.1
and the widget(s) structure still follow as same as this ?
http://ellislab.com/forums/viewthread/109584/#552514
and this version don’t need to load any variable from the config ??
i see earlier version have this…..
#75 / Nov 29, 2011 3:42am
If you use Modular Extensions HMVC then you can load the Widget class as a plugin as described in this thread. Otherwise you should load the Widget class as a helper.