Jump to content
Larry Ullman's Book Forums

Jonathon

Members
  • Posts

    1064
  • Joined

  • Last visited

  • Days Won

    55

Everything posted by Jonathon

  1. Yii2 has just been released as a public preview for those interested. http://www.yiiframework.com/news/71/yii-2-public-preview-available/
  2. Thanks Larry, That was doing my head in. I was trying to place if(isset... statements in there which failed. Thanks Jonathon
  3. Hi, I've been using $this->setState('first_name', $user->first_name); To set the first name of a user and use this value within a menu. However when I try to hide the menu if the user isn't logged in I get the error message above in the title. Whcih I understand. I just don't know how to overcome this in Yii. Sure it's simple. If someone could help me out that would be great. Here is the menu code. ... code above .... 'buttons'=>array( array('visible'=> !Yii::app()->user->isGuest, 'label'=>Yii::app()->user->first_name, 'items'=>array( This code works fine once logged in. Just not when a user is not logged in Thanks
  4. I've never had any problems with HostGator, their service has been excellent for me, I can access things outside my webroot too, customer service on live chat is great, there isn't anything that I've needed that hasn't been available to me (so far). Just my experience. Slightly off topic I know. GoDaddy I know are limited in what they offer however a friend used them.
  5. No need to apologise at all. Just thought i'd give you a time frame in case you needed it.
  6. I think the former generally applies to me. I enjoy how easy the model relations are with Yii to use (For the most part, sometimes they can be a little complex). I'd like to cut down on the lazy loading of aspects of a query with lots of joins. For the moment It will do though. Yii is still very quick I find!
  7. Yes, I've been unable to access it server 500 error for about 24-36 hours. Thanks Larry
  8. Sorry Larry, Basically the actionView() for my Item Controller has a lovely view using the CDetailView widget. It shows all the related table info using Giix. As you know. I need to show this data using a CListView widget as it's multiple records not a CDetailView one. It's meant to list all the Items for one particular area. I basically wasn't sure how to do that. or if what i'm trying to is possible. I could make an SQL query that loads it all, it is fairly long and has 4 or 5 joins. Which I don't mind doing. But I wondered if there was a better way within Yii using relations etc. That is my question I guess. My logic of how it fits together is. Which please discard if it confuses you was: I go to the example.com/area/areaID/area-name - Yii uses the areaID from url to start the query to find all Items that are from this area. - Yii returns all the Item id numbers - I then use the loadModel() method to load each record into an array - Pass this array to the page that lists all the items from an area Does that make sense? Sorry for the confusion Please ignore me for the moment. I think i've sorted this. It was far simpler, I don't think I used the relations properly. Apologies! I just need to tidy up some of the lazy loading which is what I'd initially expect with so many relations.
  9. Have you updated the config file to hide the index.php file?
  10. This question is somewhat related to the start of this thread. In my Area/index I am listing all the items that are available from a particular Area by using the Area PK to search the Item table. I have quite a lot of related information. I've recently started using Giix and it has brilliant views (in general) that it will list all the data from a table and it's related table. How would I be able to pass this model to the CListView widget instead of the $dataProvider. I can do this with a pure sql statement that was rather complex, but then I thought there must be a better way than this. My area of confusion here is that the model in the nice view is the item Model (Not Area Model) and is loaded through the actionView() method and loadModel function. Which takes an Item($id) and loads that data and related tables info. But for the CListView widget I am just using Area id to find related items that have the same area_id. Therefore missing out on the nicely preloaded related model values. To refresh this is the current Area code $dataProvider=new CActiveDataProvider('Item', array( 'criteria' => array( 'with' =>'Area', 'condition' => 't.area_id=:id', // primary Item table `area_id` = id passed in url 'params' => array(':id'=>$id) ), 'sort'=>array( 'attributes'=>array( 'title'=>array( 'asc'=>'title', 'desc'=>'title DESC' ), 'price'=>array( 'asc'=>'price', 'desc'=>'price DESC' ) ) ), 'pagination'=>array( 'pageSize'=>5, ) )); $this->render('index',array( 'dataProvider'=>$dataProvider, )); This only way I can think of currently, is calling the Area id and using it find all the Item records that have that area_id, then using each record's PK (id) and then prefroming the loadModel() function to get all the related information and return it as one huge multidimensional array or array of objects. But this seems like it would complicated, messy and beyond me. Although it is 1.15AM so I might just be tired. Is there an easier way or should I just use my sql query to call it all? Thanks Jonathon
  11. I'm having a look at the Giix extension. I just made another copy of my practice site and renamed it. I notice the code is very similar in places. Just wanted to check over a couple of things. I notice it doesn't list a postOnly + delete in the filter, but in the actionDelete code it states public function actionDelete($id) { if (Yii::app()->getRequest()->getIsPostRequest()) { $this->loadModel($id, 'Item')->delete(); if (!Yii::app()->getRequest()->getIsAjaxRequest()) $this->redirect(array('admin')); } else throw new CHttpException(400, Yii::t('app', 'Your request is invalid.')); } Does if (Yii::app()->getRequest()->getIsPostRequest()). Basically mean the same as the filter. It would appear so. Also noted that in the Giix version of a controller it uses the $model->setAttributes=$_POST['Item']; where as the standard Gii method uses $model->attributes=$_POST['Item'];. I wondered why the slight difference. I looked at the framework notes for this but couldn't really understand the difference in the two methods. Other than the setAttributes method does seem to clearly defined as a setter. Other than that the controllers are very similar for those interested. I shall have to have a play with using data and related tables. Jonathon
  12. Thanks Larry, I'll have a play with it, see how I get on! Jonathon
  13. Hi Larry, I was wondering if (When you get a spare minute). If you could let me know your experiences with the Giix extension. I read about it in your book and it seemed really helpful. However this is the first time i've used Yii so I wondered if any changes it creates in comparison to regular Gii might be hard to pick up for someone new to Yii like me, some of the methods seem to change to things like "GxActiveForm" for instance. I liked what you and it has to say about better handling of related tables as I do have a lot on related tables. And from reading between the lines it seems that if you make changes to your DB after you start it would be easier to update the code. Thanks Jonathon
  14. Thanks for the help Larry. That fixed it. As a side note though. I had to use the YiiBooster widget to get the nav bar to display properly.
  15. Hi Larry, Thank you, I need to look into it more. I do like my drop down log in box. But i'm not sure that I really need full site wide SSL.So maybe I won't use it for Logins.
  16. I actually built my demo site without using any bootstrap extensions. So this chapter I am looking forward to reading. This is currently how my code is set up config/main.php // application components 'components'=>array( 'bootstrap' => array( 'class' => 'ext.bootstrap.components.Bootstrap', 'responsiveCss'=>true, ), layout/main.php <div class="nav-collapse collapse"> <?php $this->widget('zii.widgets.CMenu',array('items'=>array( array('label'=>'Home', 'url'=>array('/site/index')), array('label'=>'About','url'=>array('/site/page', 'view'=>'about')), array('label'=>'Contact','url'=>array('/site/contact')), array('label'=>'Login', 'url'=>array('/site/login'), 'visible'=>Yii::app()->user->isGuest), array('label'=>'Logout ('.Yii::app()->user->name.')', 'url'=>array('/site/logout'),'visible'=>!Yii::app()->user->isGuest), ), 'htmlOptions' => array('class'=>'nav') )); ?> </div><!--/.nav-collapse --> When I load my page. I don't have a lovely boostrap bar. I don't seem to have any boostrap files brought in or anything either. So I then thought i'd try the breadcrumb part out. Now this throws the following error: Alias "bootstrap.widgets.TbBreadcrumbs" is invalid. Make sure it points to an existing directory or file. So i'm deducing that somewhere along the way I have an incorrect directory path. That may be wrong, but wondered if anyone could shed some light. I will continue to try and get to the bottom of this. I've also checked my permissions on Windows 7. Normally I don't think they are very strict however.
  17. Hi Larry, Yes it was a weird message, I didn't see how it related. Here is some of the stack. "throw new CException(Yii::t('yii','{controller} cannot find the requested view "{view}".'," If you want to do that feel free to, but don't feel obligated. It seems to be generated by just calling a __construct() inside Controller.php. What would your thoughts be on when a login, change password etc would need SSL? It's an area i'm not really sure on.
  18. Thank you Larry. I tried to use a constructor and this actually fails in that in creates the error: SiteController cannot find the requested view. (Replace controller and view with whatever view/controller you're after depending on the page accessed). Another thought struck me though. I had planned to use SSL on Login, logout, verify, register, change pass and forgot pass pages. Now I don't know your thoughts on that as it is. I just read an article sometime ago. But having a drop down login box in my navigation bar would therefore require me to make the whole site HTTPS I would think. Which is something I asked on here a while ago and generally peoples thoughts were not to do that.
  19. Hi Larry, Thatnks for the pointer with layouts. I think i've sorted this now. However I've run into another problem with a drop down form in my nav bar. I placed the code in the actionIndex() method of the site controller. But when I use another controller say Area I get the following error Fatal error: Call to a member function getValidators() on a non-object in C:\xampp\yii-1-1-12\framework\web\helpers\CHtml.php I'm assuming because I explored this problem that because my code to pass the loginModel is only prevalent in the SiteController's actionIndex() method that I can't access it when another controller is in use. Which makes sense. The error seems to occur from the line <?php echo CHtml::activeTextField($this->loginModel, 'email', array('placeholder'=>'Your Email', 'class'=>'drop-login')); ?> Which is how I've come to this conclusion. as when I comment it out the page loads. But I'm not sure how to make it available to every controller without creating redundancies. I have /** * @var object of LoginForm() type. For use with passing loginForms to all pages */ public $loginModel; in my Controller.php, but you said I need to assign $loginModel a value (of new LoginForm) at some point. I'm unsure where to do this though so it's available to all controllers? Jonathon
  20. Hi Larry, Thanks for your help, this is how I did this for anyone interested. Controller.php /** * @var object of LoginForm() type. For use with passing loginForms to all pages */ public $loginModel; SiteController.php // Login Form model for nav bar $loginModel = new LoginForm(); $this->loginModel = $loginModel; Layout.php <?php echo CHtml::activeTextField($this->loginModel, 'email', array('placeholder'=>'Your Email', 'class'=>'drop-login')); ?> <?php echo CHtml::activePasswordField($this->loginModel, 'password', array('placeholder'=>'Password', 'class'=>'drop-login')); ?> Thanks for all your help, although I am still wondering about the layout question I posed in my previous post. Thanks Jonathon
  21. Hi Larry, Thanks for that, I'll take a look and see how I get on. On a related note, I feel like I may be using layouts incorrectly in that I have 3 different layouts. But each time I replicate the code for the nav bar and footer. What's the way round this?
  22. Oh sorry, The layout file is where the code (The 2nd part) for the form resides.In my case layouts/home.php and the $loginModel is returned as undefined when I access the index page.
  23. Hi, I have a working login form. But I also have a little drop down login in my nav bar. I'm currently trying to create the form properly through Yii using active fields. I'm a little unsure of how to do this though. In particular of passing the LoginForm model to the pages. I have tried in my SiteController actionIndex() // Login Form model for nav bar $loginModel = new LoginForm(); // render index view $this->render('index',array( // other models 'loginModel'=>$loginModel, )); And then tried to use it in the layout file like so: echo CHtml::beginForm(array('site/login'), 'post'); ?> <?php echo CHtml::activeTextField($loginModel, 'username', '', array('placeholder'=>'Your Email')); ?> <?php echo CHtml::activePasswordField($loginModel,'password', '', array('placeholder'=>'Password')); ?> // rest of form But it always returns undefined. Where am I going wrong? Thanks Jonathon
×
×
  • Create New...