Jump to content
Larry Ullman's Book Forums


  • Posts

  • Joined

  • Last visited

Everything posted by melaniecarr23

  1. I have two tables: -players -registrations Each Registrations record can have many Players associated with it. My registration/create action gives me a syntax error: syntax error, unexpected '$registration' (T_VARIABLE)Can someone help me see what I'm doing wrong to make this work? It's one of the biggest pieces of the puzzle I need to work locally before I can see if it works online. I created a controller named RegistrationController.php <?php namespace backend\controllers; use Yii; use backend\models\Registrations; use backend\models\Players; use backend\models\search\RegistrationsSearch; use yii\web\Controller; use yii\web\NotFoundHttpException; use yii\filters\VerbFilter; use yii\helpers\Json; use yii\helpers\ArrayHelper; use yii\base\Exception; /** * RegistrationController implements the CRUD actions for registration and players models. */ class RegistrationController extends Controller { public function actionCreate() { $registration = new Registrations(); $players = []; for ($i = 0; $i < 5; $i++) { $players[] = new Players(); } if ($registration->load(Yii::$app->request->post()) { $registration->save(); } if (Model::loadMultiple($players, Yii::$app->request->post()) { foreach ($players as $player) { $player->regsitrationID = $registration->ID; $player->save(); } } return $this->render('create',[ 'registration'=>$registration, 'players' => $players, ]); } } My create.php is the standard and rendersPartial _form.php (which is below): <?php use yii\helpers\Html; use yii\widgets\ActiveForm; use yii\web\View; use backend\models\registration; use backend\models\players; use backend\models\registrations; /* @var $this yii\web\View */ /* @var $model backend\models\registration */ /* @var $form yii\widgets\ActiveForm */ ?> <div class="form"> <?php $form=$this->beginWidget('CActiveForm', array( 'id'=>'user-form', 'enableAjaxValidation'=>false, )); ?> <p class="note">Fields with <span class="required">*</span> are required.</p> <div class="row"> <?= $form->field($registration, 'transactionID')->hiddenInput(['value'=>'2'])->label(false) ?> <?= $form->field($registration, 'divisionLevelID')->dropDownList($model->DivisionLevelAssignmentList, [ 'prompt' => 'Please Choose One' ]);?> <?= $form->field($registration, 'field')->dropDownList($model->FieldsList, [ 'prompt' => 'Please Choose One' ]);?> <?= $form->field($registration, 'net')->textInput() ?> <?= $form->field($registration, 'team')->textInput() ?> <?= $form->field($registration, 'notes')->textarea(['rows' => 6]) ?> </div> ////////////////////////////////////////////////////// <h2>Player 1 Info</h2> <div class="row"> <?= $form->field($players, '[]first')->textInput(['maxlength' => true]) ?> <?= $form->field($players, '[]last')->textInput(['maxlength' => true]) ?> <?= $form->field($players, '[]phone')->textInput(['maxlength' => true]) ?> <?= $form->field($players, '[]email')->textInput(['maxlength' => true]) ?> </div> ////////////////////////////////////////////////////// <h2>Player 2 Info</h2> <div class="row"> <?= $form->field($players, '[]first')->textInput(['maxlength' => true]) ?> <?= $form->field($players, '[]last')->textInput(['maxlength' => true]) ?> <?= $form->field($players, '[]phone')->textInput(['maxlength' => true]) ?> <?= $form->field($players, '[]email')->textInput(['maxlength' => true]) ?> </div> ////////////////////////////////////////////////////// <h2>Player 3 Info</h2> <div class="row"> <?= $form->field($players, '[]first')->textInput(['maxlength' => true]) ?> <?= $form->field($players, '[]last')->textInput(['maxlength' => true]) ?> <?= $form->field($players, '[]phone')->textInput(['maxlength' => true]) ?> <?= $form->field($players, '[]email')->textInput(['maxlength' => true]) ?> </div> ////////////////////////////////////////////////////// ////////////////////////////////////////////////////// <h2>Player 4 Info</h2> <div class="row"> <?= $form->field($players, '[]first')->textInput(['maxlength' => true]) ?> <?= $form->field($players, '[]last')->textInput(['maxlength' => true]) ?> <?= $form->field($players, '[]phone')->textInput(['maxlength' => true]) ?> <?= $form->field($players, '[]email')->textInput(['maxlength' => true]) ?> </div> ////////////////////////////////////////////////////// <?php $this->endWidget(); ?> </div><!-- form -->
  2. This was solved by using &PlayersSearch[registrationID]=29 instead of just &registrationID=29.
  3. I want to be able to click on a link from the registration gridview, and filter the results of the players gridview so only the players I selected show up. Right now, it's not filtering. I get all the players. I have the following tables: - registrations - players From the registrations/index gridview I have a link so I can edit players: <?= DynaGrid::widget([ 'columns' => [ ['attribute'=>'playersEditLink', 'format'=>'raw'], [ 'label'=>'Player(s)', 'format' => 'raw', 'value' => function ($dataProvider) { $str = ''; foreach($dataProvider->players as $name) { $str .= ' '; $str .= $name->first.' '; $str .= $name->last.'<br />'; } return nl2br($str); }, 'filter' => function ($dataProvider) { $str = ''; foreach($dataProvider->players as $name) { $str .= ' '; $str .= $name->first.' '; $str .= $name->last.'<br />'; } return nl2br($str); }, ], //'transactionID', // divisionLevel dropdown editable column [ 'class' => 'kartik\grid\EditableColumn', 'header' => 'Division Level', 'attribute' => 'divisionLevelID', 'value' => 'divisionLevelName', 'pageSummary' => true, 'editableOptions'=> function ($model, $key, $index, $widget) { $divisionlevels = ArrayHelper::map(DivisionLevelAssignment::find()->where(['active'=>1])->orderBy('divisionlevelID')->asArray()->all(),'divisionlevelID','exportName'); return [ 'header' => 'Division Level', 'size' => 'sm', 'inputType' => 'dropDownList', 'displayValueConfig' => $divisionlevels, 'data' => $divisionlevels ]; } ], // field dropdown editable column [ 'class' => 'kartik\grid\EditableColumn', 'attribute' => 'field', 'value' => 'fieldName', 'pageSummary' => true, 'editableOptions'=> function ($model, $key, $index, $widget) { $fields = ArrayHelper::map(Fields::find()->all(), 'id','name'); return [ 'header' => 'Field', 'size' => 'sm', 'inputType' => 'dropDownList', 'displayValueConfig' => $fields, 'data' => $fields ]; } ], // editable net column [ 'class'=>'kartik\grid\EditableColumn', 'attribute'=>'net', 'editableOptions'=>[ 'header'=>'Net', 'inputType'=>'textInput', 'options'=>['pluginOptions'=>['min'=>1, 'max'=>60]] ], 'hAlign'=>'right', 'vAlign'=>'middle', 'width'=>'50px' ], // editable team column [ 'class'=>'kartik\grid\EditableColumn', 'attribute'=>'team', 'editableOptions'=>[ 'header'=>'Team #', 'inputType'=>'textInput', 'options'=>['pluginOptions'=>['min'=>1, 'max'=>5]] ], 'hAlign'=>'right', 'vAlign'=>'middle', 'width'=>'50px' ], // 'team', // 'notes:ntext', ['class' => 'yii\grid\ActionColumn'], ], 'storage'=>DynaGrid::TYPE_SESSION, 'theme'=>'panel-danger', 'gridOptions'=>[ 'dataProvider'=>$dataProvider, 'filterModel'=>$searchModel, 'panel'=>['heading'=>'<h3 class="panel-title">Library</h3>'], ], 'options'=>['id'=>'dynagrid-1'] // a unique identifier is important ]); ?> This gives me a column that links to players/index&registrationID=29 My problem here is that I can't seem to get the GridView for Players to filter results so only players with a registrationID = 29 will show up. PlayersController: public function actionIndex() { $searchModel = new PlayersSearch(); if (isset($_GET['registrationID'])) $searchModel->attributes = $_GET['registrationID']; $dataProvider = $searchModel->search(Yii::$app->request->queryParams); return $this->render('index', [ 'searchModel' => $searchModel, 'dataProvider' => $dataProvider, ]); } PlayersSearchModel: public function search($params) { $query = players::find(); // add conditions that should always apply here $dataProvider = new ActiveDataProvider([ 'query' => $query, ]); // setup sorting attributes BEFoRE $this->load($params) $dataProvider->setSort([ 'attributes' =>[ 'ID', 'registrationID', 'fullName' => [ 'asc' => [ 'first' => SORT_ASC, 'last' => SORT_ASC], 'desc' => [ 'first' => SORT_DESC, 'last' => SORT_DESC], 'label' => 'Full Name', 'default' => SORT_ASC ], 'email', 'phone', 'city', 'state', ] ]); if (isset($_GET['PlayersSearch']) && !($this->load($params) && $this->validate())) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); $query->joinWith(['registration']); return $dataProvider; } // grid filtering conditions $query->andFilterWhere(['ID' => $this->ID]); $query->andFilterWhere(['registrationID' => $this->registrationID]); $query->andFilterWhere(['first' => $this->first]); $query->andFilterWhere(['last' => $this->last]); $query->andFilterWhere(['email' => $this->email]); $query->andFilterWhere(['phone' => $this->phone]); $query->andFilterWhere(['city' => $this->city]); $query->andFilterWhere(['state' => $this->state]); $query->andWhere('first LIKE "%' . $this->fullName . '%" ' . 'OR last LIKE "%' . $this->fullName . '%"'); return $dataProvider; }
  4. Yii1 I actually am working on two sites (my own and one I volunteer to help a nonprofit with). The original guy did the site using Yii, but from what I'm able to see, he didn't do a lot of it the Yii way and it's making my life hell). This is the nonprofit site and is using yii1 locally running mamp pro on my macbook, and remotely hosted at digital ocean using Ubuntu. mysql is the db for both. I wish I could just drive out to State College one day and soak up everything from you like a sponge!
  5. admin/views/registrations/admin.php <?php $this->breadcrumbs = array( $model->label(2) => array('index'), Yii::t('app', 'Manage'), ); $this->menu = array( array('label'=>Yii::t('app', 'List') . ' ' . $model->label(2), 'url'=>array('index')), array('label'=>Yii::t('app', 'Create') . ' ' . $model->label(), 'url'=>array('create')), ); Yii::app()->clientScript->registerScript('search', " $('.search-button').click(function(){ $('.search-form').toggle(); return false; }); $('.search-form form').submit(function(){ $.fn.yiiGridView.update('registrations-grid', { data: $(this).serialize() }); return false; }); "); ?> <h1><?php echo Yii::t('app', 'Manage') . ' ' . GxHtml::encode($model->label(2)); ?></h1> <p> You may optionally enter a comparison operator (<, <=, >, >=, <> or =) at the beginning of each of your search values to specify how the comparison should be done. </p> <?php echo GxHtml::link(Yii::t('app', 'Advanced Search'), '#', array('class' => 'search-button')); ?> <div class="search-form collapse"> <?php $this->renderPartial('_search', array( 'model' => $model, )); ?> </div><!-- search-form --> <?php $this->widget('application.modules.admin.extensions.booster.widgets.TbExtendedGridView', array( 'id' => 'registrations-grid', 'dataProvider' => $model->search(), 'filter' => $model, 'type' => 'striped bordered condensed', 'columns' => array( array( 'name' => 'ID', 'type'=>'raw', 'value'=>'CHtml::link($data->ID,Yii::app()->createUrl("admin/players/registrationlinked/",array("id"=>$data->ID)))', ), array( 'name'=>'transactionID', 'value'=>'GxHtml::valueEx($data->transaction)', // change to text search ), array( 'name'=>'divisionLevelID', 'header'=>'Division', 'value'=>'GxHtml::valueEx($data->divisionLevel->division)', ), array( 'name'=>'divisionLevelID', 'header'=>'Level', 'value'=>'GxHtml::valueEx($data->divisionLevel->level)', ), array( 'name'=>'field', 'value'=>'GxHtml::valueEx($data->field0)', 'filter'=>GxHtml::listDataEx(Fields::model()->findAllAttributes(null, true)), ), // filters appropriately array( 'name' => 'net', 'header' => 'Net', 'class' => 'application.modules.admin.extensions.booster.widgets.TbEditableColumn', 'headerHtmlOptions' => array('style' => 'width:30px'), 'editable' => array( 'type' => 'text', 'url' => $this->createUrl('registrations/editable') ) ), array( 'name' => 'team', 'header' => 'Team #', 'class' => 'application.modules.admin.extensions.booster.widgets.TbEditableColumn', 'headerHtmlOptions' => array('style' => 'width:30px'), 'editable' => array( 'type' => 'text', 'url' => $this->createUrl('registrations/editable') ) ), array( 'name' => 'notes', 'header' => 'Notes', 'class' => 'application.modules.admin.extensions.booster.widgets.TbEditableColumn', 'headerHtmlOptions' => array('style' => 'width:30px'), 'editable' => array( 'type' => 'text', 'url' => $this->createUrl('registrations/editable') ) ), /* */ array( 'class' => 'CButtonColumn', ), ), )); ?> Thought maybe some of my code with the widgets in it might help. I've tried referencing the booster widgets various ways: booster.widgets.TbExtendedGridView ext.booster.widgets.TbExtendedGridView (when I had booster in the protected/extensions folder) admin.extensions.booster.widgets.TbExtendedGridView (after I moved it to the protected/modules/admin/extensions folder and finally application.admin.extensions.bosoter.widgets.TbExtendedGridView This is a big huge bummer. I'm ready to pay someone for a few minutes to fix things for me, or even just to take a look at my site and guide me through what I'm missing to make things work.
  6. I was able to follow everything you wrote in the book on yii booster and modules and tested everything locally on my mac using MAMP. It worked great. Dropdown menus, tables with dropdown related filtering, editable fields, toggle fields. Beautiful amazing module! I uploaded it to the server and can't get booster to work at all. I changed my yii booster menu to a CMenu version and it works, so I know it's got something to do with how I'm initializing or configuring yii booster. main.php (I can't change the way URLs are done or preload booster for the whole site) 'modules'=>array( // uncomment the following to enable the Gii tool 'gii'=>array( 'class'=>'system.gii.GiiModule', 'password'=>'bypass', // If removed, Gii defaults to localhost only. Edit carefully to taste. 'ipFilters'=>array('','','::1','2601:46:4200:3214:fc19:fc58:7775:6454','*'), //enable extension giix 'generatorPaths' => array( 'ext.giix-core'), ), 'admin' => array( // admin module by Melanie 'class' => 'application.modules.admin.AdminModule', 'components' => array( 'booster' => array( 'class' => 'admin.extensions.booster.components.Booster'), ), 'preload' => array('booster'), ), 'pay', // sample stripe payment module ), // application components 'components'=>array( 'booster' => array( 'class' => 'application.modules.admin.extensions.booster.components.Booster', 'responsiveCss'=>true, ), 'user'=>array( // enable cookie-based authentication 'allowAutoLogin'=>false, ), // prevent CSRF attacks when using cookies set to true // must use CHtml or CActiveForm to create forms to work //'request'=>array( // 'enableCsrfValidation'=>true, //), 'session' => array( 'class' => 'CDbHttpSession', 'autoCreateSessionTable' => true, 'connectionID' => 'db', 'timeout' => 2400, 'autoStart' => true ), // uncomment the following to enable URLs in path-format 'urlManager'=>array( //'urlFormat'=>'path', 'rules'=>array( //'http://admin.pottstownrumble.net' => 'admin/default/index', //'http://admin.pottstownrumble.net/login' => 'admin/default/login', //'http://admin.pottstownrumble.com' => 'admin/default/index', //'http://admin.pottstownrumble.com/login' => 'admin/default/login', //'<controller:\w+>/<id:\d+>'=>'<controller>/view', //'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>', //'<controller:\w+>/<action:\w+>'=>'<controller>/<action>', ), ), AdminModule.php <?php class AdminModule extends CWebModule { public function init() { Yii::app()->setComponents(array( 'errorHandler' => array( 'errorAction' => 'admin/default/error'), 'user' => array( 'class' => 'CWebUser', 'loginUrl' => Yii::app()->createUrl('admin/default/login'), ) )); Yii::app()->user->setStateKeyPrefix('admin'); // 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( 'admin.models.*', 'admin.components.*', 'admin.extensions.*', )); } 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 $route = $controller->id . '/' . $action->id; // echo $route; $publicPages = array( 'default/login', 'default/error', ); if (Yii::app()->user->isGuest && !in_array($route, $publicPages)){ Yii::app()->user->loginRequired(); } else return true; } else return false; } } DefaultController.php <?php class DefaultController extends Controller { public $layout = 'xadmin'; /*public function filters() { return array( array('booster.filters.BoosterFilter - delete') ); }*/ public function actionIndex() { $this->render('index'); } /** * Displays the login page */ public function actionLogin() { $model=new LoginForm; // if it is ajax validation request if(isset($_POST['ajax']) && $_POST['ajax']==='login-form') { echo CActiveForm::validate($model); Yii::app()->end(); } // collect user input data if(isset($_POST['LoginForm'])) { $model->attributes=$_POST['LoginForm']; // validate user input and redirect to the previous page if valid if($model->validate() && $model->login()) $this->redirect(Yii::app()->user->returnUrl); } // display the login form $this->render('login',array('model'=>$model)); } /** * Logs out the current user and redirect to homepage. */ public function actionLogout() { Yii::app()->user->logout(false); $this->redirect(Yii::app()->getModule('admin')->user->loginUrl); } public function actionError() { if($error=Yii::app()->errorHandler->error) { if(Yii::app()->request->isAjaxRequest) echo $error['message']; else $this->render('error', $error); } } } Directory Structure: Protected->Modules->admin->extensions is where I put the booster folder I downloaded from the clever tech site. Originally I had it in the Protected->extensions folder, and it worked fine that way until I uploaded it. Then it didn't work. All I got was a blue line across the top of the screen. Can someone help me figure out how to run yii booster on all pages of the admin module? Thanks, Melanie
  7. Thanks. I abandoned this thought, and decided to instead try developing everything new in Yii 2 and publish when it's done.
  8. I don't know what I did to mess it up, but I got this working.
  9. I figured out what I was doing wrong. I now just use the admin.php view for both, but with different controller actions. public function actionAdminLinked($id) { $model = new Registrations('search'); if (isset($_GET['Registrations'])) $model->setAttributes($_GET['Registrations']); $model->ID = $id; $this->render('admin', array( 'model' => $model, )); } public function actionDivisionlevel($id) { $model = new Registrations('search'); if (isset($_GET['Registrations'])) $model->setAttributes($_GET['Registrations']); $model->divisionLevelID = $id; $this->render('admin', array( 'model' => $model, )); } I still don't know how to display the many players for each registration in the GridView, if anyone has a clue please help!
  10. I have been using the Yii Book to create an admin module for a site I didn't create that uses the yii framework. I was able to successfully create the module, apply login functionality to it, and implement Yii booster for extendedgrid functionality with inline editing. I can link the text from a column using the foreign key relation to a different model's view (primary key) and display those results using the TbExtendedGridView. What doesn't seem to work for me is displaying the results according to a different attribute other than the primary key. Link: http://mysites.com/index.php?r=admin/registrations/adminlinked&id=29 http://mysites.com/index.php?r=admin/registrations/divisionLevel&id=3 RegistrationController: public function actionAdminLinked($id) { $model = $this->loadModel($id, 'Registrations'); $this->performAjaxValidation($model, 'registrations-form'); if (isset($_POST['Registrations'])) { $model->setAttributes($_POST['Registrations']); if ($model->save()) { $this->redirect(array('view', 'id' => $model->ID)); } } $this->render('adminlinked', array( 'model' => $model, )); } public function actionDivisionlevel($id) { $model=Registrations::model()->with('divisionLevel','division','level','players')->findAllByAttributes(array( 'divisionLevelID'=>$id, )); $this->performAjaxValidation($model, 'registrations-form'); $this->render('adminlinked', array( 'model' => $model, )); } Note: I'd like to add the ability to display player names (2 to 4 depending on the registration), division and level names (through divisionLevel relations). actionAdminLinked displays results correctly. actiondivisionLevel displays a blank screen. What on earth am I doing wrong that I can't seem to get this to work? I've tried for hours.
  11. Yes, I was following an article I found online since I realized it wasn't easy for me to migrate from yii1 to yii2 and I wanted to use the newer version.
  12. Okay I'm still going through the book and I LOVED the Booster plugin but I don't get the Giix plugin at all. I installed it and ran the giix model and giix crud for tables that are related but the code generated for my one model doesn't even show the admin page. It's just a blank white screen! I look for documentation on how to use the features of this extension and there isn't any! Just issues. What am I missing. I can't see supporting an extension that doesn't help you figure out what you can do with it. MANY_MANY relationships with lookup tables are my freaking nemesis. I can't figure out how to use Yii to work with them easily.
  13. I have Yii 1.1.16 installed and had been using the yii book to help me. I installed yii2 with the intention of using the suggestion for running both at the same time, and the yii book 2 helped with the installation but I can't seem to get it to work. My error is: Fatal error: Call to undefined method Yii::registerAutoloader() in /home/drcarr/protected/components/Yii.php on line 16 I could use some help fixing it, or suggestions on changing my yii1 site into a yii2 site that also runs from the main directory of the domain.
  • Create New...