Commits

nucklearproject committed 4b7148e

Updates

  • Participants
  • Parent commits 58df06d

Comments (0)

Files changed (12)

File protected/components/SimpleCart.php

 <?php
-
+/**
+ * Your var declaration
+ * @var SimpleCart
+ */
 class SimpleCart  extends CApplicationComponent
 {
 	
 	/**
 	 * Insert items into the cart and save it to the session table
 	 *
-	 * @param	array
+	 * @param	array $items
 	 * @return	bool
 	 */
 	public function insert($items = array())

File protected/config/main.php

 
 	// preloading 'log' component
 	'preload'=>array('log'),
-	
-	
+
+
 	// autoloading model and component classes
 	'import'=>array(
 		'application.models.*',
 
 	'modules'=>array(
 		// uncomment the following to enable the Gii tool
-		'test',
-		
+		'test', 'modulewidget',
+
 		'gii'=>array(
 			'class'=>'system.gii.GiiModule',
 			'password'=>'admin',
 		 	// If removed, Gii defaults to localhost only. Edit carefully to taste.
 			'ipFilters'=>array('127.0.0.1','::1'),
 		),
-		
+
 	),
 
 	// application components
 	'components'=>array(
-		
+
 		'session' => array (
 		'class' => 'system.web.CDbHttpSession',
 		'connectionID' => 'db',
 		'sessionTableName' => 'session',
 		),
-		
+
 		'cart' => array('class' => 'SimpleCart'),
-		
+
 		'user'=>array(
 			// enable cookie-based authentication
 			'allowAutoLogin'=>true,
 		),
 		// uncomment the following to enable URLs in path-format
-		
+
 		'urlManager'=>array(
 			'urlFormat'=>'path',
 			'showScriptName' => false,
 				'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
 			),
 		),
-				
+
 		/* database include */
-		
+
 		'db'=> require(dirname(__FILE__) . '/db.php'),
-		
+
 		'errorHandler'=>array(
 			// use 'site/error' action to display errors
             'errorAction'=>'site/error',

File protected/controllers/LibroController.php

 
 class LibroController extends Controller {
 
-  /**
-   * @var string the default layout for the views. Defaults to '//layouts/column2', meaning
-   * using two-column layout. See 'protected/views/layouts/column2.php'.
-   */
-  public $layout = '//layouts/column2';
-
-  /**
-   * @return array action filters
-   */
-  public function filters() {
-    return array(
-        'accessControl', // perform access control for CRUD operations
-    );
-  }
-
-  /**
-   * Specifies the access control rules.
-   * This method is used by the 'accessControl' filter.
-   * @return array access control rules
-   */
-  public function accessRules() {
-    return array(
-        array('allow', // allow all users to perform 'index' and 'view' actions
-            'actions' => array('index', 'view'),
-            'users' => array('*'),
-        ),
-        array('allow', // allow authenticated user to perform 'create' and 'update' actions
-            'actions' => array('create', 'update'),
-            'users' => array('@'),
-        ),
-        array('allow', // allow admin user to perform 'admin' and 'delete' actions
-            'actions' => array('admin', 'delete'),
-            'users' => array('admin'),
-        ),
-        array('deny', // deny all users
-            'users' => array('*'),
-        ),
-    );
-  }
-
-  /**
-   * Displays a particular model.
-   * @param integer $id the ID of the model to be displayed
-   */
-  public function actionView($id) {
-    $this->render('view', array(
-        'model' => $this->loadModel($id),
-    ));
-   
-  }
-
-  /**
-   * Creates a new model.
-   * If creation is successful, the browser will be redirected to the 'view' page.
-   */
-  public function actionCreate() {
-    $model = new Libro;
-
-
-    // Uncomment the following line if AJAX validation is needed
-    // $this->performAjaxValidation($model);
-
-    if (isset($_POST['Libro'])) {
-      $model->attributes = $_POST['Libro'];
-      if ($model->save())
-        $this->redirect(array('view', 'id' => $model->id));
-    }
-
-    $this->render('create', array(
-        'model' => $model,
-    ));
-  }
-
-  /**
-   * 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['Libro'])) {
-      $model->attributes = $_POST['Libro'];
-      if ($model->save())
-        $this->redirect(array('view', 'id' => $model->id));
-    }
-
-    $this->render('update', array(
-        'model' => $model,
-    ));
-  }
-
-  /**
-   * Deletes a particular model.
-   * If deletion is successful, the browser will be redirected to the 'admin' page.
-   * @param integer $id the ID of the model to be deleted
-   */
-  public function actionDelete($id) {
-    if (Yii::app()->request->isPostRequest) {
-      // we only allow deletion via POST request
-      $this->loadModel($id)->delete();
-
-      // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
-      if (!isset($_GET['ajax']))
-        $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));
-    }
-    else
-      throw new CHttpException(400, 'Invalid request. Please do not repeat this request again.');
-  }
-
-  /**
-   * Lists all models.
-   */
-  public function actionIndex() {
-    $dataProvider = new CActiveDataProvider('Libro');
-    $this->render('index', array(
-        'dataProvider' => $dataProvider,
-    ));
-  }
-
-  /**
-   * Manages all models.
-   */
-  public function actionAdmin() {
-    $model = new Libro('search');
-    $model->unsetAttributes();  // clear any default values
-    if (isset($_GET['Libro']))
-      $model->attributes = $_GET['Libro'];
-
-    $this->render('admin', array(
-        'model' => $model,
-    ));
-  }
-
-  /**
-   * Returns the data model based on the primary key given in the GET variable.
-   * If the data model is not found, an HTTP exception will be raised.
-   * @param integer the ID of the model to be loaded
-   */
-  public function loadModel($id) {
-    $model = Libro::model()->findByPk($id);
-    if ($model === null)
-      throw new CHttpException(404, 'The requested page does not exist.');
-    return $model;
-  }
-
-  /**
-   * Performs the AJAX validation.
-   * @param CModel the model to be validated
-   */
-  protected function performAjaxValidation($model) {
-    if (isset($_POST['ajax']) && $_POST['ajax'] === 'libro-form') {
-      echo CActiveForm::validate($model);
-      Yii::app()->end();
-    }
-  }
+	/**
+	 * @var string the default layout for the views. Defaults to '//layouts/column2', meaning
+	 * using two-column layout. See 'protected/views/layouts/column2.php'.
+	 */
+	public $layout = '//layouts/column2';
+
+	/**
+	 * @return array action filters
+	 */
+	public function filters() {
+		return array('accessControl', // perform access control for CRUD operations
+		);
+	}
+
+	/**
+	 * Specifies the access control rules.
+	 * This method is used by the 'accessControl' filter.
+	 * @return array access control rules
+	 */
+	public function accessRules() {
+		return array( array('allow', // allow all users to perform 'index' and 'view' actions
+		'actions' => array('index', 'view'), 'users' => array('*'), ), array('allow', // allow authenticated user to perform 'create' and 'update' actions
+		'actions' => array('create', 'update'), 'users' => array('@'), ), array('allow', // allow admin user to perform 'admin' and 'delete' actions
+		'actions' => array('admin', 'delete'), 'users' => array('admin'), ), array('deny', // deny all users
+		'users' => array('*'), ), );
+	}
+
+	/**
+	 * Displays a particular model.
+	 * @param integer $id the ID of the model to be displayed
+	 */
+	public function actionView($id) {
+		$this -> render('view', array('model' => $this -> loadModel($id), ));
+
+	}
+
+	/**
+	 * Creates a new model.
+	 * If creation is successful, the browser will be redirected to the 'view' page.
+	 */
+	public function actionCreate() {
+		$model = new Libro;
+
+		// Uncomment the following line if AJAX validation is needed
+		// $this->performAjaxValidation($model);
+
+		if (isset($_POST['Libro'])) {
+			$model -> attributes = $_POST['Libro'];
+			if ($model -> save())
+				$this -> redirect(array('view', 'id' => $model -> id));
+		}
+
+		$this -> render('create', array('model' => $model, ));
+	}
+
+	/**
+	 * 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['Libro'])) {
+			$model -> attributes = $_POST['Libro'];
+			if ($model -> save())
+				$this -> redirect(array('view', 'id' => $model -> id));
+		}
+
+		$this -> render('update', array('model' => $model, ));
+	}
+
+	/**
+	 * Deletes a particular model.
+	 * If deletion is successful, the browser will be redirected to the 'admin' page.
+	 * @param integer $id the ID of the model to be deleted
+	 */
+	public function actionDelete($id) {
+		if (Yii::app() -> request -> isPostRequest) {
+			// we only allow deletion via POST request
+			$this -> loadModel($id) -> delete();
+
+			// if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
+			if (!isset($_GET['ajax']))
+				$this -> redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));
+		} else
+			throw new CHttpException(400, 'Invalid request. Please do not repeat this request again.');
+	}
+
+	/**
+	 * Lists all models.
+	 */
+	public function actionIndex() {
+		$dataProvider = new CActiveDataProvider('Libro');
+		$this -> render('index', array('dataProvider' => $dataProvider, ));
+	}
+
+	/**
+	 * Manages all models.
+	 */
+	public function actionAdmin() {
+		$model = new Libro('search');
+		$model -> unsetAttributes();
+		// clear any default values
+		if (isset($_GET['Libro']))
+			$model -> attributes = $_GET['Libro'];
+
+		$this -> render('admin', array('model' => $model, ));
+	}
+
+	/**
+	 * Returns the data model based on the primary key given in the GET variable.
+	 * If the data model is not found, an HTTP exception will be raised.
+	 * @param integer the ID of the model to be loaded
+	 */
+	public function loadModel($id) {
+		$model = Libro::model() -> findByPk($id);
+		if ($model === null)
+			throw new CHttpException(404, 'The requested page does not exist.');
+		return $model;
+	}
+
+	/**
+	 * Performs the AJAX validation.
+	 * @param CModel the model to be validated
+	 */
+	protected function performAjaxValidation($model) {
+		if (isset($_POST['ajax']) && $_POST['ajax'] === 'libro-form') {
+			echo CActiveForm::validate($model);
+			Yii::app() -> end();
+		}
+	}
 
 }

File protected/controllers/TestcartController.php

 <?php
 
-class TestcartController extends Controller {
-
-  /**
-   * @var string the default layout for the views. Defaults to '//layouts/column2', meaning
-   * using two-column layout. See 'protected/views/layouts/column2.php'.
-   */
-  public $layout = '//layouts/column2';
-  
-	public function actionIndex(){
-
-		$data = array(
-                'id'      => 'sku_123ABC',
-                'qty'     => 2,
-                'price'   => 39.00,
-                'name'    => 'T-Shirt',
-                'options' => array('Size' => 'L', 'Color' => 'Red')
-             );
-			 
-			 $data2 = array(
-                'id'      => 'sku_123ABCJJJ',
-                'qty'     => 1,
-                'price'   => 39.00,
-                'name'    => 'T-Shirt',
-                'options' => array('Size' => 'M', 'Color' => 'Red')
-             );
-			 
-			 $data3 = array(
-                'id'      => 'sku_123ABCJJJDDD',
-                'qty'     => 1,
-                'price'   => 39.00,
-                'name'    => 'T-Shirt',
-                'options' => array('Size' => 'M', 'Color' => 'Red')
-             );
-	
-	$update = array(
-                'rowid' => '0256a32c98ce49afbe2a4eb8c96c5884',
-				'qty' => 5
-             );
-		//$cart = new SimpleCart();
-		Yii::app()->cart->insert($data);
-		Yii::app()->cart->insert($data2);
-		Yii::app()->cart->insert($data3);
-		
-		
-		
-	
-
-//Yii::app()->cart->destroy();
-//Yii::app()->session['uno'] = $data;
-//var_dump(Yii::app()->session['uno']);
-//var_dump(Yii::app()->cart->contents());
-
-//echo "<hr>";
-//Yii::app()->cart->update($update);
-//var_dump(Yii::app()->session['cart_contents']);
-
-//echo "<hr>";
-//echo Yii::app()->cart->format_number(Yii::app()->cart->total());
-
-	}
-	
-	public function actionList(){
-		
-		$this->render('products');
-	}
-	
-	public function update(){
-	
-		
-	
-	}
-  
-  }
+class TestcartController extends Controller
+{
+
+    /**
+     * @var string the default layout for the views. Defaults to '//layouts/column2', meaning
+     * using two-column layout. See 'protected/views/layouts/column2.php'.
+     */
+    public $layout = '//layouts/column2';
+
+    public function actionIndex()
+    {
+
+        $data = array('id'      => 'sku_123ABC',
+                      'qty'     => 2,
+                      'price'   => 39.00,
+                      'name'    => 'T-Shirt',
+                      'options' => array('Size'  => 'L',
+                                         'Color' => 'Red'));
+
+        $data2 = array('id'      => 'sku_123ABCJJJ',
+                       'qty'     => 1,
+                       'price'   => 39.00,
+                       'name'    => 'T-Shirt',
+                       'options' => array('Size'  => 'M',
+                                          'Color' => 'Red'));
+
+        $data3 = array('id' => 'sku_123ABCJJJDDD', 'qty' => 1, 'price' => 39.00, 'name' => 'T-Shirt', 'options' => array('Size' => 'M', 'Color' => 'Red'));
+
+        $update = array('rowid' => '0256a32c98ce49afbe2a4eb8c96c5884', 'qty' => 5);
+        //$cart = new SimpleCart();
+        Yii::app()->cart->insert($data);
+        Yii::app()->cart->insert($data2);
+        Yii::app()->cart->insert($data3);
+
+
+        //Yii::app()->cart->destroy();
+        //Yii::app()->session['uno'] = $data;
+        //var_dump(Yii::app()->session['uno']);
+        //var_dump(Yii::app()->cart->contents());
+
+        //echo "<hr>";
+        //Yii::app()->cart->update($update);
+        //var_dump(Yii::app()->session['cart_contents']);
+
+        //echo "<hr>";
+        //echo Yii::app()->cart->format_number(Yii::app()->cart->total());
+
+    }
+
+    public function actionList()
+    {
+
+        $this->render('products');
+
+    }
+
+    public function update()
+    {
+
+    }
+
+}

File protected/data/yii.db

Binary file modified.

File protected/modules/modulewidget/ModulewidgetModule.php

+<?php
+
+class ModulewidgetModule extends CWebModule
+{
+	public function init()
+	{
+		// this method is called when the module is being created
+		// you may place code here to customize the module or the application
+
+		// import the module-level models and components
+		$this->setImport(array(
+			'modulewidget.models.*',
+			'modulewidget.components.*',
+		));
+	}
+
+	public function beforeControllerAction($controller, $action)
+	{
+		if(parent::beforeControllerAction($controller, $action))
+		{
+			// this method is called before any module controller action is performed
+			// you may place customized code here
+			return true;
+		}
+		else
+			return false;
+	}
+}

File protected/modules/modulewidget/controllers/DefaultController.php

+<?php
+
+class DefaultController extends Controller
+{
+	public function actionIndex()
+	{
+		$this->render('index');
+	}
+}

File protected/modules/modulewidget/controllers/MywidgetController.php

+<?php
+
+class MywidgetController extends Controller
+{
+	public function actionIndex()
+	{
+		$this->render('index');
+	}
+
+	// Uncomment the following methods and override them if needed
+	/*
+	public function filters()
+	{
+		// return the filter configuration for this controller, e.g.:
+		return array(
+			'inlineFilterName',
+			array(
+				'class'=>'path.to.FilterClass',
+				'propertyName'=>'propertyValue',
+			),
+		);
+	}
+
+	public function actions()
+	{
+		// return external action classes, e.g.:
+		return array(
+			'action1'=>'path.to.ActionClass',
+			'action2'=>array(
+				'class'=>'path.to.AnotherActionClass',
+				'propertyName'=>'propertyValue',
+			),
+		);
+	}
+	*/
+}

File protected/modules/modulewidget/views/default/index.php

+<?php
+/* @var $this DefaultController */
+
+$this->breadcrumbs=array(
+	$this->module->id,
+);
+?>
+<h1><?php echo $this->uniqueId . '/' . $this->action->id; ?></h1>
+
+<p>
+This is the view content for action "<?php echo $this->action->id; ?>".
+The action belongs to the controller "<?php echo get_class($this); ?>"
+in the "<?php echo $this->module->id; ?>" module.
+</p>
+<p>
+You may customize this page by editing <tt><?php echo __FILE__; ?></tt>
+</p>

File protected/modules/modulewidget/views/mywidget/index.php

+
+<h1><?php echo $this->id . '/' . $this->action->id; ?></h1>
+
+<p>
+	Contenikdo del modulo modulewidgetYou may change the content of this page by modifying
+	the file <tt><?php echo __FILE__; ?></tt>.
+</p>

File protected/views/site/index.php

 <p>For more details on how to further develop this application, please read
 the <a href="http://www.yiiframework.com/doc/">documentation</a>.
 Feel free to ask in the <a href="http://www.yiiframework.com/forum/">forum</a>,
-should you have any questions.</p>
+should you have any questions.</p>
+
+<?php Yii::app()->getModule('modulewidget'); ?>

File protected/views/testcart/products.php

 
 <div class="row buttons">
 		<?php echo CHtml::submitButton('Update Cart'); ?>
-	</div>
+</div>
 
 <?php CHtml::endForm(); ?>