[MODULE] p3widgets

Phundament 3 - Widgets

P3WidgetsModule provides basic Content Management System (CMS) functionality through a widget container for frontend-editing and a backend for managing widget properties and content.

A widget container tags its contents (widgets) by its id, the current controller and action and optionally also by a request parameter.

When you edit a widget you can specify its type (see config value modules[p3widgets].params[widgets]), its attributes by editing them with a built-in JSON editor and its content by editing it with a built-in ckeditor.

Database schema setup is done easily with yiic migrate.

Installation, Download, etc: http://www.yiiframework.com/extension/p3widgets/

I hooked up the widget, but the set does not come out. I added




'widgets' => array(

     'CWidget' => 'Basic Widget',

     'zii.widgets.CMenu' => 'Menu bar'

)



In the widgets added entry




Alias	zii.widgets.CMenu

Properties	{"items":{"":{"label":"Home","url":"http://strat.ua"}}}

Content	<p> ffghfghfghgfh</p>



Text [b] ffghfghfghgfh [/ b] conclusions, as there is no menu. In what may be the problem?

Thanks!

Hi mc.aser,

I do not have fix right now, but at least I found the problem.

The problem is, that I am using beginWidget() and endWidget() to render the widget with its contents.

But somehow I also have to call the run()-method of the widget to display the CMenu - this should be done by endWidget(), but it does not work.

CWidget, line 144:


	/**

	 * Executes the widget.

	 * This method is called by {@link CBaseController::endWidget}.

	 */

	public function run()

	{

	}



I will investigate that…

Thanks for your feedback & best regards,

schmunk

Could you check this fix?

https://github.com/schmunk42/phundament/commit/0ad69b1d6f8b1bcef46656cca57c2ede8ceb9366

Simply exchange the file /protected/modules/p3widgets/components/P3WidgetContainer.php

https://github.com/schmunk42/phundament/blob/master/protected/modules/p3widgets/components/P3WidgetContainer.php

I Fixed this by adding $properties in


$this->controller->beginWidget($class, $properties); 

.

I looked you did too:). It works.

Still do not understand how it works requestParam.

Yes, another change to the




$criteria->condition = '(controllerId = '' OR controllerId = :controllerId) AND (actionName = '' OR actionName = :actionName) AND containerId = :containerId';



This allows the unit to all actions of the controller or the entire site in general, such units as the main menu, the advertising zone or follow tweeter.

Thank you for your work!

:)

In the Yii app skeleton you have the about page, which is rendered by the site controller, action page and request parameter view ($_GET[‘view’]).

If you add another view test you can access it with ?r=site/page&view=test.

If you would now not varyByRequestParam view containers in both views would display the same widgets (if they have have the same id).

With a CMS for example you would have a CmsController and an id for every page and you would use the same template view for different pages and then you’d have to varyByRequestParam to select the correct widgets.

Maybe this parameter could also be an array to handle multiple values, but this would make selecting the records more difficult.

Yesss! You got it dude! :D That’s very basic part of the concept.

I had that in Phundament 2, will be implemented soon ;)

Would be cool to see you on GitHub with a fork!

Demo updated: http://demo.phundament.com/3.0-dev

JSON Editor is a good way if you know alle the Widget-Attributes. However most of my users and customers don’t know all attributes.

So i added a form. This form has to be in the widget Folder with the same name as the widget + "Form". So "BasicWidget" -> "BasicWidgetForm".

The Form is dynamically updating when you choose a different Widget.

I can upload an Screencast if someone is interested.

Here is the code:

../views/widget/_form.php (You need to enable JQuery ) line 0:


<script type="text/javascript">

    $(document).ready(function() {

        $("#formBox").load("<?php echo $this->createUrl("GetForm"); ?>?form=" +

            $("#Widget_alias :selected").val() + "&id=<?php echo $model->id ?>" );

        $("select").change(function () {

            $("#formBox").load("<?php echo $this->createUrl("GetForm"); ?>?form=" +

                $("#Widget_alias :selected").val() + "&id=<?php echo $model->id ?>" );

        });

    });


</script>  

Somewhere in the form-container:


    <div id="formBox">




    </div> 

WidgetController




/**

     * Updates a particular model.

     * If update is successful, the browser will be redirected to the 'view' page.

     * @param integer $id the ID of the model to be updated

     */

    public function actionUpdate($id) {

        $model = $this->loadModel($id);


        // Uncomment the following line if AJAX validation is needed

        // $this->performAjaxValidation($model);


        if (isset($_POST['Widget'])) {

            $model->attributes = $_POST['Widget'];

            if ($_POST['Form'])

                $model->properties = json_encode($_POST['Form']);

            

            $criteria = new CDbCriteria();

            $criteria->params = array(

                ':controllerId' => $model->controllerId,

                ':actionName' => $model->actionName,

                ':containerId' => $model->containerId,

                ':rank' => $model->rank,

            );

            $criteria->condition = 'actionName = :actionName AND containerId = :containerId AND controllerId = :controllerId AND rank = :rank';

            if ($model->save()) {

                $this->redirect(array('view', 'id' => $model->id));

            }

        }

        $this->render('update', array(

            'model' => $model

                ), false, true);

    }

And add this function to WidgetController:


    public function actionGetForm($id) {

        if($id){

            $properties = json_decode($this->loadModel($id)->properties);

        }

        $form = $_GET['form'] . "Form";

        if ($this->getViewFile($form)) {

            $this->renderPartial($form,array('properties'=> $properties));

        } else {

            return true;

        }

    }

Then you can add form to your Widget

Exampe BasicWidgetForm




<fieldset class="no-border">

    <label for="Form[events_headline]">Überschrift</label>

    <input name="Form[events_headline]" id="name" type="text" class="text" maxlength="" value="<?php echo $properties->events_headline ?>">


  

</fieldset>

Hopefully you get an idea. I think it is pretty useful.

Best regards,

Peili

Hi peili,

thanks for your idea.

Have you seen the semi-automatic property detection in the latest release?

I had the stuff with custom forms in phundament 2, similar like you’ve suggested it.

I think this would be also a useful feature for Phundament 3, but had no time to code this yet.

Could you fork p3widgets on github?

Best regards,

schmunk