Jump to content
Larry Ullman's Book Forums

Edward

Members
  • Posts

    1115
  • Joined

  • Last visited

  • Days Won

    27

Everything posted by Edward

  1. Here is the array i will use to render the inbox in the views, this is getting ugly, which is why i think saving html data in the database may be more appropriate. Please excuse my poor Yii coding, i am just hacking away here. public function getInboxMessages($id) { // Make an array for inbox messages $message = array(); $criteria = new CDbCriteria(); $criteria->condition = 'user_id=:user_id'; $criteria->params = array(':user_id'=>$id); $modelInbox = $this->model()->findAll($criteria); if($modelInbox===null) { throw new CHttpException(404,'The requested page does not exist.'); } else { foreach($modelInbox as $message) { if($message->type=='offer') { $modelSender = User::model()->findByPk($message->sender_id); $sender_username = $modelSender->username; $from = CHtml::link($sender_username, Yii::app()->createUrl('$sender_username')); $icon = '<i class="icon-hand-right"></i>'; $modelOffer = Offer::model()->with('action')->findByPk($message->type_id); $modelAction = $modelOffer->action; $thread_id = $modelAction->thread_id; $modelThread = Thread::model()->findByPk($thread_id); $item_id = $modelThread->item_id; $modelItem = Item::model()->findByPk($item_id); $item_title = $modelItem->title; $link = CHtml::link($item_title, Yii::app()->createUrl('$item_title')); $messages[] = array("from" => $from, "icon" => $icon, "link" => $link, "date" => $message->date); } } } return $messages; } Here was the view rendering part <?php /* @var $this InboxController */ /* @var $dataProvider CActiveDataProvider */ $this->breadcrumbs=array( 'Inbox', ); ?> <h1>Message Inbox</h1> <table class="table table-bordered"> <tr class="info"> <td><strong>From</strong></td> <td><i></i></td> <td><strong>Subject</strong></td> <td><strong>Date Received</strong></td> </tr> <?php $messages = Inbox::model()->getInboxMessages(4); foreach($messages as $message) { echo '<tr class="warning">'; echo "<td>".$message['from']."</td>"; echo "<td>".$message['icon']."</td>"; echo "<td>".$message['link']."</td>"; echo "<td>".$message['date']."</td>"; echo '</tr>'; } ?> </table>
  2. I heard some people online that said they changed their websites from .net to .com and they said the .com got more traffic. People said that when people went to search in google they would type in for example if they were looking for clothes they would type clothes.com so then the .net's would not be in the search. From my research it was the only information i could find that is why i want to ask more here. I quite like .net as it is the abreviation for network which does sound more appropriate for my website.
  3. I started to code my message inbox, i have an inbox table and i first tried generating the links for the inbox when rendering it but this seems like a huge process. So the other idea would be to create the links and save them to the inbox database table with the html code. This process would seem to be less exhaustive. So do you think saving links in the database with html code is okay?
  4. Its hard these days to domain names as everyone registers the good ones to sell. I found a .com domain but the only problem is the first word is a slang word and not the formal word. I did manage to get the .net version of the formal name but i am not sure whether to go ahead with this or use the slang word .com domain. The person that has the formal .com domain wants 2 millon dollars for it. I noticed online that ebid.net seemed to have done really well even though they are .net, can anyone help me make a final decision on the domain name.
  5. I know you want Larry to answer you so i won't bother replying to your other questions but i found a cool way to access the array of objects so now it is not longer a pain. $modelInbox = $this->model()->findAll($criteria); if($modelInbox===null) { throw new CHttpException(404,'The requested page does not exist.'); } else { foreach($modelInbox AS $message) { echo $message->column1; echo $message->column2; } } The other way you can get the elements out of the objects array i tried was ugly, i used print_r function to obtain information to get this: echo $model[0]['attributes']['item_id'];
  6. For the sticky part you you need to change $POST to $_POST that will fix that.
  7. I used MAMP snd it worked perfect i thought that was the most suitable server package for Mac, my name is a Edward could i be wrong?
  8. If that is for drawing out a list of categories for index put it into the category model. Also how you pass the data to the view file is fine. You could also put the method name in the array in the render method. Personally i think it would be better just calling the model method from views because you do the same thing with dropdownlist.
  9. Some of your question above also depends on what the tables you have on your site have in relation to one another. If you have related tables you can use the relational active record, this will save you having to do the joining yourself. I know joins are really fun but if you work with Yii you can get the stuff done faster, the only downfall with Active record is that the queries are slower. I think working with the active record on these join statements would be the best way for now then when your site gets busy you can work on performance tuning later on and make your own raw sql statements etc. If you wanted your controller to be better managed you could move that sql code into a model method and just have it return the results the other thing would be to put a class into the components folder that would contain related methods. I have done a lot of AR and RAR stuff now, but the bitch is when you are doing the Relational join with a has many relationship you get an array of objects, which for me now is a pain to access.
  10. Glad to see the new Yii chapters are out, looks well written as usual. Sessions look easy to use, that was something i didn't need up till now but will need when i have my shopping cart up and working. Now i am working on the transactions stuff of the site, i have 15 models and 6 controllers so far. There are a lot more things to build in, i think i am only about 10% complete off a whole site. Haha and the forms chapter you wrote looks very familiar to me, its all good stuff.
  11. Thanks Larry i really appreciate your quick answer, i was stumped with that diagram on the Yii Website. I'll put the category ID in the items table that makes everything much easier. Once again thanks.
  12. Looks like i have not worked this out, i am confused with the example in the definitive guide and am still debating on whether a post_category table would be required? I have setup the intermediary table but the problem is now how to access it with Active Record. This is similar to the Yii Book tbl_page_has_file database, how do we update this the Yii way? I can see in Yii that is a many to many relationship but with the category situation i have i only have one category per item so i ask again do we need the extra table? I will work on some other stuff now until someone comes up with a explanation.
  13. I think i have worked this out myself, if we don't have the intermediary table there is no way for Yii to be able to use Relational Active Record to connect a product to the category with the foreign key. The only way would be to write raw sql which is a waste of code since we have the Relational Active Record to do the work for us.
  14. The ClientID, ProgramType are both numerical values so you don't need to quote them as you have done the string values. So you could try this: insert into tblRehabilitationHistory (ClientID, ProgramType, When, Where, HowLong) values (2, 1, '2009', 'Brisbane', '6 weeks');
  15. I have been checking our the Relational Active Record in the YiiFramework guide. http://www.yiiframew...en/database.arr I am a little confused about the ER Diagram, why do they have a tbl_post_category table when the could of just put the column category_id within the post table. As far as i see it even with the tbl_post_category you would still end up having repeated column values, so what is the point in that?
  16. Relational active record can be tricky, i made a with statement to fetch two related models with a primary key. But for one of the relations i was returned and object as it had a Belongs To relationship. But for other that had a Has Many relationship relational active records returned an array. I couldn't find much documentation on this but i was able to access the data via the array. I also noticed that Yii had not generated all relationships in the models so today i had to fill them in. Just wanted to let you know what i have experienced.
  17. You can try the headers_sent() function if it returns boolean it means something was already sent to the web browsers. The headers already sent could also be the result of a php closing tag, that script 3.1 you are modifying is an include file, check the closing tag on that if there is one remove it. Also another thing you probably already know just a reminder here is about the output buffering that can be useful in stopping the headers already sent. Check out ob_start(), ob_end_flush() and ob_end_clean().
  18. I guess you could make your own widget for the getYears() method which needs to be reusable. You could add a full class to the components folder but that method would be better if it was a class with several related methods. If you just needed a small bit of code that had nothing in relation to it then i would go with making your own widget. Here is a link to how to do that in the Yii Definitive Guide. http://www.yiiframework.com/doc/guide/1.1/en/extension.create
  19. It would be worth investing your time in learning the Yii Framework it has built in validators like url which will quickly valid a URL and which have been thoroughly tested. Yii will help you to be able to build more bug free professional websites and with 3 times the speed. Which also means more money for you as a web developer as you can get more projects done.
  20. Ah yeah and about the get the root of all yii classes extend from the Ccomponent Class that is where you get or set problem lies. https://github.com/yiisoft/yii/blob/1.1.13/framework/base/CComponent.php /** * Returns a property value, an event handler list or a behavior based on its name. * Do not call this method. This is a PHP magic method that we override * to allow using the following syntax to read a property or obtain event handlers: * <pre> * $value=$component->propertyName; * $handlers=$component->eventName; * </pre> * @param string $name the property name or event name * @return mixed the property value, event handlers attached to the event, or the named behavior * @throws CException if the property or event is not defined * @see __set */ public function __get($name) { $getter='get'.$name; if(method_exists($this,$getter)) return $this->$getter(); elseif(strncasecmp($name,'on',2)===0 && method_exists($this,$name)) { // duplicating getEventHandlers() here for performance $name=strtolower($name); if(!isset($this->_e[$name])) $this->_e[$name]=new CList; return $this->_e[$name]; } elseif(isset($this->_m[$name])) return $this->_m[$name]; elseif(is_array($this->_m)) { foreach($this->_m as $object) { if($object->getEnabled() && (property_exists($object,$name) || $object->canGetProperty($name))) return $object->$name; } } throw new CException(Yii::t('yii','Property "{class}.{property}" is not defined.', array('{class}'=>get_class($this), '{property}'=>$name))); } /** * Sets value of a component property. * Do not call this method. This is a PHP magic method that we override * to allow using the following syntax to set a property or attach an event handler * <pre> * $this->propertyName=$value; * $this->eventName=$callback; * </pre> * @param string $name the property name or the event name * @param mixed $value the property value or callback * @return mixed * @throws CException if the property/event is not defined or the property is read only. * @see __get */ public function __set($name,$value) { $setter='set'.$name; if(method_exists($this,$setter)) return $this->$setter($value); elseif(strncasecmp($name,'on',2)===0 && method_exists($this,$name)) { // duplicating getEventHandlers() here for performance $name=strtolower($name); if(!isset($this->_e[$name])) $this->_e[$name]=new CList; return $this->_e[$name]->add($value); } elseif(is_array($this->_m)) { foreach($this->_m as $object) { if($object->getEnabled() && (property_exists($object,$name) || $object->canSetProperty($name))) return $object->$name=$value; } } if(method_exists($this,'get'.$name)) throw new CException(Yii::t('yii','Property "{class}.{property}" is read only.', array('{class}'=>get_class($this), '{property}'=>$name))); else throw new CException(Yii::t('yii','Property "{class}.{property}" is not defined.', array('{class}'=>get_class($this), '{property}'=>$name))); }
  21. Edward

    Twitter Bootstrap

    Yeah i am still trying to get my head around it, it is to me in some words a miracle, i thought i was going to have to spend hours and hours trying to figure out that CSS stuff myself. Now we have lots of time for development thanks to TB and Yii.
  22. I had some trouble with CHtml::listData it would not work correctly in one of my situations. So what i done is create an array manually then the sent the array from the model to the dropdown function in the view and it worked perfectly. For example here was some of my model code: public function getShippingServiceOptions() { $list = array(); $list['']='Select a shipping service'; $list['service1']='Economy services from outside US'; $list['1']='Economy Shipping from outside US (11 to 23 business days)'; $list['service2']='Standard services from outside US'; $list['5']='Standard Shipping from outside US (5 to 10 business days)'; $list['service3']='Expedited services from outside US'; $list['10']='Expedited Shipping from outside US (1 to 4 business days)'; $list['econony-services']='Economy Services'; $services = $this->findAll('type=:type', array(':type'=>'economy-service')); foreach($services as $service) { $list[$service->id]=$service->description; } return $list; } I don't think there would be much difference between this and putting together a first name and last name.
  23. Edward

    Twitter Bootstrap

    I am sure there will be many self millionaires made from your books. I don't think you can put a price on what your knowledge is worth.
  24. Yii has a long history starting off with prado. No idea what kind of experience the other guys have nor have i ever heard of them. If i was you i would try to find something that has been around for a while tried and tested. There are many people online saying things are good but as you know the internet can be fulled with bullshits comments.
×
×
  • Create New...